-
-
Notifications
You must be signed in to change notification settings - Fork 3k
HTTPResponse is not recognized as a subtype of typing.IO #3108
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
Comments
I think this kind of problems could be solved by protocols. I have encountered many similar issues recently. I will probably submit a PR today or tomorrow. (Note that extensive changes to typeshed may be required, replacing nominal types with corresponding protocols). |
The IO types are especially complicated; there are lots of different "file-like" types with subtly different sets of methods. Maybe somebody will need to spend the time to carefully review all file-like types in the standard library to come up with a good set of protocols. |
This came up again in python/typeshed#2188 (comment) it seems. |
This seems like a typeshed bug, not a mypy bug. |
I've copied this issue to typeshed: python/typeshed#2189 |
From SO:
This fails with
Argument 1 to "copyfileobj" has incompatible type "Union[HTTPResponse, BinaryIO]"; expected IO[Any]
becauseHTTPResponse
derives fromio.BufferedIOBase
, which (despite being a binary IO) does not derive fromtyping.BinaryIO
(nor doesio.RawIOBase
; alsoio.IOBase
does not derive fromtyping.IO
).When I attempted to derive them as I thought would make sense, I got errors because
__enter__
and other methods are defined both inio.IOBase
and intyping.BinaryIO
.Not sure how to solve it.
The text was updated successfully, but these errors were encountered: