Repository navigation
Closed
Description
The python 2 stubs have the class variables:
Lines 40 to 48 in 67e38b6
| class HTTPConnection: | |
| response_class = ... # type: Any | |
| default_port = ... # type: Any | |
| auto_open = ... # type: Any | |
| debuglevel = ... # type: Any | |
| strict = ... # type: Any | |
| timeout = ... # type: Any | |
| source_address = ... # type: Any | |
| sock = ... # type: Any |
but the python 3 stubs do not:
typeshed/stdlib/3/http/client.pyi
Lines 127 to 141 in f6b60cb
| class HTTPConnection: | |
| if sys.version_info >= (3, 4): | |
| def __init__( | |
| self, | |
| host: str, port: Optional[int] = ..., | |
| timeout: int = ..., | |
| source_address: Optional[Tuple[str, int]] = ... | |
| ) -> None: ... | |
| else: | |
| def __init__( | |
| self, | |
| host: str, port: Optional[int] = ..., | |
| strict: bool = ..., timeout: int = ..., | |
| source_address: Optional[Tuple[str, int]] = ... | |
| )-> None: ... |
This causes a mypy error with the following:
error: "Type[HTTPConnection]" has no attribute "debuglevel"
If all that needs to be done is to add the hints for those class variables, then I don't mind making a PR to do so.
Please let me know if I should make the PR or if I have the error wrong and the problem is somewhere else.
Metadata
Metadata
Assignees
Labels
No labels
Activity
gvanrossum commentedon Feb 19, 2018
Hmmm... Those attributes are not documented, so I'm not sure it would be a good idea to add them to the stubs. I'm not sure why they exist in the Python 2 stubs.
This kind of question has come up a few times recently. I wonder if we need to have a general ruling on what to do with undocumented/unsupported attributes. Is it better to have mypy flag those, so you know your code is doing something fishy, or is it better to make mypy silent? There's no other tool that I know of that is capable of flagging the use of undocumented attributes, so I'm kind of leaning towards seeing this as a valuable service mypy (or rather, typeshed) provides, rather than a deficiency in the stubs. For example, if we were to add these attributes to the stubs, IDEs like PyCharm would start suggesting auto-completion for undocumented attributes, which I definitely think is a bad idea. (If there's something that's commonly used, you should petition for it to be included in the docs first.)
scottbelden commentedon Feb 19, 2018
I like the idea of these undocumented attributes being flagged. I didn't know that
debuglevelwas undocumented, but I see thatset_debuglevelis the proper way to do it, so I can call that instead.As far as actual discussion on flagging vs not flagging undocumented/unsupported attibutes, perhaps that should be in a separate issue (I'm not sure if that should be in typeshed or mypy) and this should be closed.
srittau commentedon Sep 11, 2018
It seems this problem was resolved using
set_debuglevel. If further fields are needed, please file a separate bug report or a PR, using the# undocumentedsyntax.