-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
TextIOWrapper
stub does not match stdlib documentation
#6061
Comments
Maybe related: #4146 |
I/O types are a mess. We generally recommend to use tight protocols in argument positions to avoid these kind of issues. That said, I'd be open to an experimental PR that changes the buffer type to |
Is there some place that the relationship between IO[bytes], IO[str], BufferdIOBase, RawIOBase and StringIOBase is defined? I know IO[...] is marked for deprecation, but I'm actually not sure what the intended replacement is. I would guess it is the ...IOBase types, but this is not made explicit. I think actually the reasoning for using IO[bytes] is that maybe TextIOWrapper works fine for both RawIOBase and BufferedIOBase, and IO[bytes] is less verbose than Union[RawIOBase,BufferedIOBase]. I will try dig into this deeper sometime to confirm. |
The general guideline is to use protocols for arguments and concrete types (derived from |
See also python/typing#829 for some discussion of this area. |
Maybe somewhat related: python/mypy#11193 |
I think maybe the root of all problems here come from #6077, if that was resolved this would be somewhat inconsequential. |
Given the response in #6077, I think this is then not a bug. But I think maybe some documentation to this effect would be good, as it was somewhat surprising behaviour to me at least. |
I think this should be closed. This problem arose because I read the Thanks for the help and information. |
The official documentation for
TextIOWrapper
implies that the underlyingbuffer
is an instance of (or implements the interface of)io.BufferedIOBase
, but typeshed annotates it asIO[bytes]
, leading to the following counterintuitive behavior:This example is reduced from a question a user asked in the #python IRC channel on Libera.net, regarding this user code in
rdflib
.Version information
The text was updated successfully, but these errors were encountered: