-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Allow Any
type to be acceptable for the msg
parameter in `logging.{info, warn, error, ...}
#1776
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
Conversation
….{info, warn, error, ...} The stdlib accepts any value here as long as it is castable to a string: https://github.com/python/cpython/blob/3.6/Lib/logging/__init__.py#L336 https://github.com/python/cpython/blob/2.7/Lib/logging/__init__.py#L319-L330 Ideally this would use Protocols but I don't see them in use in typeshed yet.
I think we've discussed this in the past and decided that non-str logging messages should be a type error, even though the logging module accepts them as an accident of implementation. |
@JelleZijlstra IMHO we should strive to not have typeshed reject valid code. AFAICT from the CPython code the |
That's fair, @gvanrossum what do you think? Protocols can be used I believe, but they don't make much of a difference here because any type is convertible to str. |
FWIW, protocols are already used in typeshed (in There is special casing in mypy, so that you can write |
In general we don't want typeshed to be stricter than the implementation --
e.g. we've ruled before that undocumented private methods still need to be
represented, at least if there are calls in the wild.
In this particular case, I'm still sad to see the logging msg argument
change from str to Any, because it will reduce opportunities to catch
errors. In my experience *usually* this is a coding mistake. It's really
too bad that there are also codebases that do this intentionally and don't
consider themselves wrong, even though the docs imply it should be a string
("The *msg* is the message format string").
How bad is this for you, Roy?
|
Merged conflict, will land when tests pass. |
Also, @rowilloa, sorry for the slow response! |
….{info, warn, error, ...} (python#1776) The stdlib accepts any value here as long as it is castable to a string: https://github.com/python/cpython/blob/3.6/Lib/logging/__init__.py#L336 https://github.com/python/cpython/blob/2.7/Lib/logging/__init__.py#L319-L330 Ideally this would use Protocols but I don't see them in use in typeshed yet.
The stdlib accepts any value here as long as it is castable to a string:
https://github.com/python/cpython/blob/3.6/Lib/logging/__init__.py#L336
https://github.com/python/cpython/blob/2.7/Lib/logging/__init__.py#L319-L330
Ideally this would use Protocols but I don't see them in use in typeshed yet.