-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Update mypy library version to 1.8.0 #3314
Conversation
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 for tackling this!
changelog/3312.feature.rst
Outdated
@@ -0,0 +1 @@ | |||
Updated mypy library version to 1.8.0 |
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.
Since this is an internal change, we don't need a changelog entry. I've added the Skip Changelog to fix the CI check.
src/urllib3/connection.py
Outdated
@@ -307,7 +307,7 @@ def putrequest( | |||
method, url, skip_host=skip_host, skip_accept_encoding=skip_accept_encoding | |||
) | |||
|
|||
def putheader(self, header: str, *values: str) -> None: | |||
def putheader(self, header: str | bytes, *values: str | bytes) -> None: |
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.
Our handling of bytes in headers is not ideal (#3072), but I would not want to block upgrading mypy because of it.
What error do you get without this change?
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.
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.
I'd say it's better to add # type: ignore
instead of adding a type hint for an unsupported type
src/urllib3/http2.py
Outdated
@@ -72,11 +72,19 @@ def putrequest( | |||
) | |||
) | |||
|
|||
def putheader(self, header: str, *values: str) -> None: | |||
def putheader(self, header: str | bytes, *values: str | bytes) -> None: |
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.
Same question, why did you need this?
src/urllib3/contrib/pyopenssl.py
Outdated
@@ -412,7 +412,12 @@ class PyOpenSSLContext: | |||
""" | |||
|
|||
def __init__(self, protocol: int) -> None: | |||
self.protocol = _openssl_versions[protocol] | |||
ssl_method = _openssl_versions.get(OpenSSL.SSL._SSLMethod(protocol)) |
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.
The addition of OpenSSL.SSL._SSLMethod
is breaking CI.
Co-authored-by: Illia Volochii <illia.volochii@gmail.com>
src/urllib3/http2.py
Outdated
self._h2_headers.append( | ||
(header.encode("utf-8").lower(), value.encode("utf-8")) | ||
) | ||
if isinstance(header, str): | ||
header_bytes = header.encode("utf-8").lower() | ||
else: | ||
header_bytes = header.lower() | ||
|
||
if isinstance(value, str): | ||
value_bytes = value.encode("utf-8") | ||
else: | ||
value_bytes = value | ||
|
||
self._h2_headers.append((header_bytes, value_bytes)) |
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.
Let's move adding support for non-str values out this PR
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.
shall we throw error for other types? or add ignore @illia-v
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.
In this PR no functional changes (new errors, etc.) are wanted because we don't add support for any new types
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.
Cool will remove the other handling
src/urllib3/contrib/pyopenssl.py
Outdated
self.protocol = _openssl_versions[protocol] | ||
ssl_method = _openssl_versions[protocol] | ||
if ssl_method is None: | ||
# Handle the case when protocol is not found | ||
raise ValueError(f"Unsupported SSL/TLS protocol: {protocol}") | ||
self.protocol = ssl_method |
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.
Please drop the change if it isn't required for successful type checking
src/urllib3/contrib/pyopenssl.py
Outdated
|
||
|
||
__all__ = ["inject_into_urllib3", "extract_from_urllib3"] | ||
|
||
|
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.
Co-authored-by: Illia Volochii <illia.volochii@gmail.com>
@pquentin Facing issue where i am getting test failure in random test. Like for the last commit it happend for 3.9 this time for macos. What could be the reason? |
We have some flakiness issues. If 90% of tests are passing and lint is passing you are probably OK. We will double check when reviewing. |
Have made all the required changes. Should we merge it? |
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 for this @Nightrider0098, here's my review:
src/urllib3/contrib/pyopenssl.py
Outdated
@@ -412,7 +412,8 @@ class PyOpenSSLContext: | |||
""" | |||
|
|||
def __init__(self, protocol: int) -> None: | |||
self.protocol = _openssl_versions[protocol] | |||
ssl_method = _openssl_versions[protocol] |
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.
Is this change needed now since _openssl_versions
has been annotated?
src/urllib3/http2.py
Outdated
self._h2_headers.append( | ||
(header.encode("utf-8").lower(), value.encode("utf-8")) | ||
) | ||
if isinstance(header, str): |
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.
I'm surprising this isn't giving a type error, if header
or value
aren't strings then header_bytes
and value_bytes
aren't defined? Should we revert the change adding the isinstance
checks?
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.
Remove is instance check and add type override
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.
LGTM, thanks! @Nightrider0098 feel free to claim the $100 bounty from our OpenCollective.
No description provided.