Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logging.getLevelName() type hints #2730

Merged
merged 1 commit into from
Jan 17, 2019
Merged

Fix logging.getLevelName() type hints #2730

merged 1 commit into from
Jan 17, 2019

Conversation

noseworthy
Copy link
Contributor

@noseworthy noseworthy commented Jan 9, 2019

logging.getLevelName() can take either an int and returns a str or
a str and returns an int when the level name (str) or level
(int) is one of the registered log levels. If the value passed in
isn't one of the registered log levels, it returns the string "level %s" % lvl where lvl is the value passed in to the function.

Updated the type hints to better reflect this functionality.

@sproshev
Copy link
Contributor

sproshev commented Jan 9, 2019

Seems that it's better to change return type to Any. See conventions and python/mypy#1693

`logging.getLevelName()` can take either an `int` and returns a `str` or
a `str` and returns an `int` when the level name (`str`) or level
(`int`) is one of the registered log levels. If the value passed in
isn't one of the registered log levels, it returns the string `"level
%s" % lvl` where `lvl` is the value passed in to the function.

Updated the type hints to better reflect this functionality.
@noseworthy
Copy link
Contributor Author

@sproshev: My bad. Missed that in the contribution guidelines. Should be fixed now!

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@srittau srittau merged commit e8c1111 into python:master Jan 17, 2019
@noseworthy noseworthy deleted the fix_logging_get_level_name_stub branch January 17, 2019 13:54
yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this pull request Jan 23, 2019
`logging.getLevelName()` can take either an `int` and returns a `str` or
a `str` and returns an `int` when the level name (`str`) or level
(`int`) is one of the registered log levels. If the value passed in
isn't one of the registered log levels, it returns the string `"level
%s" % lvl` where `lvl` is the value passed in to the function.
cjwatson added a commit to cjwatson/typeshed that referenced this pull request Jun 3, 2024
To better reflect the implementation's behaviour,
python#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 is all arguably a bit unfortunate in light of
python#1842 (comment),
but I don't want to relitigate that here.  I've at least left a comment.
srittau pushed a commit that referenced this pull request Jun 4, 2024
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.
max-muoto pushed a commit to max-muoto/typeshed that referenced this pull request Sep 8, 2024
To better reflect the implementation's behaviour,
python#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants