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

Type http.client.HTTPConnection.sock #8386

Merged
merged 3 commits into from
Jul 26, 2022
Merged

Conversation

@github-actions

This comment has been minimized.

@sobolevn
Copy link
Member Author

sobolevn commented Jul 25, 2022

Oh, I see. Looks like the idea behind Any here is that different subtypes can use different sock types. What's is the policy in this case?

Do we fallback to Any or do we require # type: ignore[override] for such cases?

@AlexWaygood
Copy link
Member

AlexWaygood commented Jul 25, 2022

This looks quite disruptive, and in practice, users can probably be confident that sock will be a socket object after .connect() has been called.

Maybe try sock: socket | Any instead, with a comment explaining that it could be None if connect() has not yet been called?

@github-actions

This comment has been minimized.

@Akuli
Copy link
Collaborator

Akuli commented Jul 25, 2022

Please add something like sock: SSLSocket | Any into HTTPSConnection. HTTPS connections never use unencrypted socket.sockets.

@sobolevn
Copy link
Member Author

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

urllib3 (https://github.com/urllib3/urllib3)
+ test/with_dummyserver/test_https.py:463: error: Item "socket" of "Union[socket, Any]" has no attribute "server_hostname"  [union-attr]
+ test/with_dummyserver/test_https.py:784: error: Item "socket" of "Union[socket, Any]" has no attribute "version"  [union-attr]
+ test/with_dummyserver/test_https.py:882: error: Item "socket" of "Union[socket, Any]" has no attribute "version"  [union-attr]

@srittau srittau merged commit abd893a into python:master Jul 26, 2022
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