Tighten annotation of logging.getLevelName (#12088)

To better reflect the implementation's behaviour,
https://github.com/python/typeshed/pull/2730 changed
`logging.getLevelName` to accept `int | str` and return `Any` (the
latter due to the need to avoid union return types).  However, this
isn't ideal if you're passing in an `int`, in which case the
implementation always returns a `str`.  Add overloads for this.
This commit is contained in:
Colin Watson
2024-06-04 09:16:53 +01:00
committed by GitHub
parent 6ddf4647a7
commit 97ccd8985a

View File

@@ -572,7 +572,14 @@ fatal = critical
def disable(level: int = 50) -> None: ...
def addLevelName(level: int, levelName: str) -> None: ...
def getLevelName(level: _Level) -> Any: ...
@overload
def getLevelName(level: int) -> str: ...
# The str -> int case is considered a mistake, but retained for backward
# compatibility. See
# https://docs.python.org/3/library/logging.html#logging.getLevelName.
@overload
def getLevelName(level: str) -> Any: ...
if sys.version_info >= (3, 11):
def getLevelNamesMapping() -> dict[str, int]: ...