Closed
Description
Currently for getLevelName
in logging
there is
def getLevelName(lvl: int) -> str: ...
However the code for it (Python 3.6.3) accepts a string argument as well:
def getLevelName(level):
"""
Return the textual representation of logging level 'level'.
If the level is one of the predefined levels (CRITICAL, ERROR, WARNING,
INFO, DEBUG) then you get the corresponding string. If you have
associated levels with names using addLevelName then the name you have
associated with 'level' is returned.
If a numeric value corresponding to one of the defined levels is passed
in, the corresponding string representation is returned.
Otherwise, the string "Level %s" % level is returned.
"""
# See Issues #22386, #27937 and #29220 for why it's this way
result = _levelToName.get(level)
if result is not None:
return result
result = _nameToLevel.get(level)
if result is not None:
return result
return "Level %s" % level
It is not clear to me from the method's docstring that the behavior of the code with respect to strings is guaranteed, though, so perhaps leaving it as int
is safer.
Metadata
Metadata
Assignees
Labels
No labels