-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix: correct headers= kwarg in HTTP[S]Connection #12704
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Would someone help me with advice here? I'm wondering if perhaps explicitly adding Or is this a catch-22, we can't enlarge the superclass type, because the subclass may be unprepared for the extra type, in case the end user receives a subclass instance typed as superclass? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! You can ignore the primer output. The urllib3 project just needs to update their annotations (or ignore the override).
You could consider just leaving str
instead of using a protocol. This leads to cleaner error output, clearer annotations, and is easier to subclass. The protocol is tighter, but I'm not sure it matters in practice. I'll accept whatever you prefer.
Updated. I wonder what brings more value, |
Diff from mypy_primer, showing the effect of this PR on open source code: urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/http2/connection.py:143: error: Signature of "putheader" incompatible with supertype "HTTPConnection" [override]
+ src/urllib3/http2/connection.py:143: note: Superclass:
+ src/urllib3/http2/connection.py:143: note: def putheader(self, header: str | bytes, *values: Buffer | str | int) -> None
+ src/urllib3/http2/connection.py:143: note: Subclass:
+ src/urllib3/http2/connection.py:143: note: def putheader(self, header: str | bytes, *values: str | bytes) -> None
|
I've found code in the library that in a nutshell did this:
And the type checker was not happy about an
int
as a header value.Apparently Python stdlib allows:
.encode("ascii")
since Python 3.0bytes.join
, which is a ReadableBuffer in typeshedReferences:
https://github.com/python/cpython/blob/v3.0/Lib/http/client.py
https://github.com/python/cpython/blob/6046c5e0298c25515ea58abc8ab87f7413e3f743/Lib/http/client.py#L831-L834
https://github.com/python/cpython/blob/3.2/Lib/http/client.py
https://github.com/python/cpython/blob/076ca6c3c8df3030307e548d9be792ce3c1c6eea/Lib/http/client.py#L961-L966