Skip to content

Conversation

@edgarrmondragon
Copy link
Contributor

No description provided.

…b.response.addinfourl | http.client.HTTPResponse`

Signed-off-by: Edgar Ramírez-Mondragón <edgarrm358@gmail.com>
@github-actions
Copy link
Contributor

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

dulwich (https://github.com/dulwich/dulwich)
+ dulwich/lfs.py:690: error: Unsupported operand types for <= ("int" and "None")  [operator]
+ dulwich/lfs.py:690: note: Left operand is of type "int | None"
+ dulwich/lfs.py:705: error: Unsupported operand types for <= ("int" and "None")  [operator]
+ dulwich/lfs.py:705: note: Left operand is of type "int | None"

spack (https://github.com/spack/spack)
+ lib/spack/spack/test/oci/urlopen.py:448: error: Argument "_urlopen" to "upload_blob" has incompatible type "Callable[[str | Request, Buffer | SupportsRead[bytes] | Iterable[bytes] | None, float | None], addinfourl | HTTPResponse]"; expected "Callable[..., HTTPResponse] | None"  [arg-type]
+ lib/spack/spack/test/oci/urlopen.py:457: error: Argument "_urlopen" to "upload_blob" has incompatible type "Callable[[str | Request, Buffer | SupportsRead[bytes] | Iterable[bytes] | None, float | None], addinfourl | HTTPResponse]"; expected "Callable[..., HTTPResponse] | None"  [arg-type]
+ lib/spack/spack/test/oci/urlopen.py:467: error: Argument "_urlopen" to "upload_blob" has incompatible type "Callable[[str | Request, Buffer | SupportsRead[bytes] | Iterable[bytes] | None, float | None], addinfourl | HTTPResponse]"; expected "Callable[..., HTTPResponse] | None"  [arg-type]

archinstall (https://github.com/archlinux/archinstall)
+ archinstall/lib/packages/packages.py:27: error: Incompatible return value type (got "addinfourl | HTTPResponse", expected "addinfourl")  [return-value]

static-frame (https://github.com/static-frame/static-frame)
+ static_frame/core/www.py:225: error: Incompatible types in assignment (expression has type "Callable[[], bytes]", variable has type "Callable[[], str]")  [assignment]
+ static_frame/core/www.py:225: error: Incompatible return value type (got "bytes", expected "str")  [return-value]

operator (https://github.com/canonical/operator)
+ ops/pebble.py:2241: error: Incompatible return value type (got "addinfourl | HTTPResponse", expected "HTTPResponse")  [return-value]

@srittau
Copy link
Collaborator

srittau commented Nov 17, 2025

Unfortunately, this would require every user of urlopen() to add a cast or isinstance check, so it's not feasible to change this. But it's a case where python/typing#566 would be useful. That said, we should add an appropriate comment to the type var, explaining the expected return types.

@edgarrmondragon
Copy link
Contributor Author

Unfortunately, this would require every user of urlopen() to add a cast or isinstance check, so it's not feasible to change this. But it's a case where python/typing#566 would be useful.

Thanks @srittau, I see that now. Even in my own code which motivated this change, I'd need to add a type assertion to make it actually work after this change.

That said, we should add an appropriate comment to the type var, explaining the expected return types.

You mean to _UrlopenRet?

@srittau
Copy link
Collaborator

srittau commented Nov 17, 2025

You mean to _UrlopenRet?

Yes. If you want to, you can change this PR accordingly. Otherwise, I'll add a comment.

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.

2 participants