mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 12:44:28 +08:00
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:
@@ -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]: ...
|
||||
|
||||
Reference in New Issue
Block a user