Skip to content

Commit

Permalink
Tighten annotation of logging.getLevelName (#12088)
Browse files Browse the repository at this point in the history
To better reflect the implementation's behaviour,
#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.
  • Loading branch information
cjwatson authored Jun 4, 2024
1 parent 6ddf464 commit 97ccd89
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion stdlib/logging/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ...
Expand Down

0 comments on commit 97ccd89

Please sign in to comment.