Skip to content

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