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

Update mypy library version to 1.8.0 #3314

Merged
merged 15 commits into from
Jan 30, 2024

Conversation

Nightrider0098
Copy link
Contributor

No description provided.

@pquentin pquentin added the Skip Changelog Pull requests that don't require a changelog entry label Jan 25, 2024
Copy link
Member

@pquentin pquentin left a 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!

@@ -0,0 +1 @@
Updated mypy library version to 1.8.0
Copy link
Member

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.

@@ -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:
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Member

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

@@ -72,11 +72,19 @@ def putrequest(
)
)

def putheader(self, header: str, *values: str) -> None:
def putheader(self, header: str | bytes, *values: str | bytes) -> None:
Copy link
Member

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?

@@ -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))
Copy link
Member

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.

@illia-v illia-v linked an issue Jan 26, 2024 that may be closed by this pull request
Comment on lines 77 to 87
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))
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Contributor Author

@Nightrider0098 Nightrider0098 Jan 26, 2024

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

Comment on lines 415 to 421
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
Copy link
Member

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



__all__ = ["inject_into_urllib3", "extract_from_urllib3"]


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

src/urllib3/contrib/pyopenssl.py Outdated Show resolved Hide resolved
@Nightrider0098
Copy link
Contributor Author

@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?

@pquentin
Copy link
Member

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.

@Nightrider0098
Copy link
Contributor Author

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?

Copy link
Member

@sethmlarson sethmlarson left a 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:

@@ -412,7 +412,8 @@ class PyOpenSSLContext:
"""

def __init__(self, protocol: int) -> None:
self.protocol = _openssl_versions[protocol]
ssl_method = _openssl_versions[protocol]
Copy link
Member

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?

self._h2_headers.append(
(header.encode("utf-8").lower(), value.encode("utf-8"))
)
if isinstance(header, str):
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

@illia-v illia-v left a 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.

@illia-v illia-v merged commit 60c4647 into urllib3:main Jan 30, 2024
28 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog Pull requests that don't require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade mypy to the latest version in CI
4 participants