8000 typing: unable to override `pool_classes_by_scheme` with a `partial`d class · Issue #3554 · urllib3/urllib3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

typing: unable to override pool_classes_by_scheme with a partiald class #3554

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

Open
asottile-sentry opened this issue Jan 24, 2025 · 0 comments

Comments

@asottile-sentry
Copy link

Subject

incredibly specific unfortunately -- https://github.com/getsentry/sentry/blob/00f7a931ef9cb9efc31658a89d85eed19a52155e/src/sentry/net/http.py#L138-L141

we have to patch all the way down to do ip address filtering in requests / urllib3 -- to override the connection creation mechanism

as a result we override pool classes and it appears the typing for this is a little too strict (dict[str, type[HTTPConnectionPool]])

Environment

Describe your environment.
At least, paste here the output of:

>>> import platform
>>> import ssl
>>> import urllib3
>>> 
>>> print("OS", platform.platform())
OS macOS-15.2-arm64-arm-64bit-Mach-O
>>> print("Python", platform.python_version())
Python 3.13.1
>>> print(ssl.OPENSSL_VERSION)
OpenSSL 3.0.15 3 Sep 2024
>>> print("urllib3", urllib3.__version__)
urllib3 2.2.2
>>> ^D

Steps to Reproduce

I don't have a good minimal reproduction but the error from mypy is as follows:

src/sentry/net/http.py:138: error: Dict entry 0 has incompatible type "str": "partial[SafeHTTPConnectionPool]"; expected "str": "type"  [dict-item]
src/sentry/net/http.py:139: error: Dict entry 1 has incompatible type "str": "partial[SafeHTTPSConnectionPool]"; expected "str": "type"  [dict-item]
Found 2 errors in 1 file (checked 6465 source files)

Expected Behavior

ideally no errors

Actual Behavior

see above


an aside -- if I adjust the annotation slightly I can get this to pass:

-pool_classes_by_scheme = {"http": HTTPConnectionPool, "https": HTTPSConnectionPool}
+pool_classes_by_scheme: dict[str, typing.Callable[..., HttpConnectionPool]] = {"http": HTTPConnectionPool, "https": HTTPSConnectionPool}

this ~slightly reduces type safety in that a call to the value of this will no longer have its arguments checked agains the shape of HTTPConnection -- but it does allow more flexibility for what values can be in the dictionary (while still preserving the return value shape)

I'll probably just # type: ignore for now though since that's the least friction

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

No branches or pull requests

1 participant
0