Skip to content

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

Merged
merged 2 commits into from
Jun 11, 2018

Conversation

rowillia
Copy link
Contributor

@rowillia rowillia commented Dec 7, 2017

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.

….{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.
@JelleZijlstra
Copy link
Member

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.

@rowillia
Copy link
Contributor Author

rowillia commented Dec 7, 2017

@JelleZijlstra IMHO we should strive to not have typeshed reject valid code. AFAICT from the CPython code the logging module is intentionally casting to a string in py2 and py3. Are Protocols valid in Typeshed yet?

@JelleZijlstra
Copy link
Member

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.

@ilevkivskyi
Copy link
Member

FWIW, protocols are already used in typeshed (in typing.py). I think it makes sense if you feel they are necessary here (I didn't follow the whole discussion).

There is special casing in mypy, so that you can write from typing import Protocol in stubs and they will work correctly (i.e. you don't need to import typing_extensions in stubs).

@gvanrossum
Copy link
Member

gvanrossum commented Dec 7, 2017 via email

@gvanrossum
Copy link
Member

Merged conflict, will land when tests pass.

@gvanrossum gvanrossum merged commit 52c02a2 into python:master Jun 11, 2018
@gvanrossum
Copy link
Member

Also, @rowilloa, sorry for the slow response!

yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this pull request Jan 23, 2019
….{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.
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.

4 participants