You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TextIO/BinaryIO: Mismatch between documentation and implementation #518
This (typing.io) defines the generic type IO[AnyStr] and aliases TextIO and BinaryIO for respectively IO[str] and IO[bytes].
In the current implementation TextIO and BinaryIO are not aliases, but instead derived from IO. I am not sure whether this is a documentation or implementation problem, but the current implementation causes problems, since values of type IO[...], and especially IO[Any] can not be assigned where TextIO or BinaryIO is expected.
It's both a documentation problem and an implementation problem!
The documentation is factually wrong, and contradicts PEP 484. But this has also been a major nuisance (I've seen a bunch of code that tried to pass an IO[something] to TextIO or BinaryIO -- even stub files).
Alas, fixing the implementation would be tough, because the subclasses define additional APIs (e.g. TextIO.encoding) or widen the acceptable range of arguments (e.g. BinaryIO.write()).
So I say we should fix the docs first (in time for 3.6.4final!) and then consider what to do about it. (Perhaps the only reasonable course of action is to recommend using IO[] for arguments and TextIO/BinaryIO for return types.)
Can you file a blocker bpo issue for the CPython docs?
Activity
gvanrossum commentedon Dec 12, 2017
It's both a documentation problem and an implementation problem!
The documentation is factually wrong, and contradicts PEP 484. But this has also been a major nuisance (I've seen a bunch of code that tried to pass an IO[something] to TextIO or BinaryIO -- even stub files).
Alas, fixing the implementation would be tough, because the subclasses define additional APIs (e.g. TextIO.encoding) or widen the acceptable range of arguments (e.g. BinaryIO.write()).
So I say we should fix the docs first (in time for 3.6.4final!) and then consider what to do about it. (Perhaps the only reasonable course of action is to recommend using IO[] for arguments and TextIO/BinaryIO for return types.)
Can you file a blocker bpo issue for the CPython docs?
srittau commentedon Dec 12, 2017
@gvanrossum I filed it as bpo-32284, but someone else needs to set the blocker priority.
srittau commentedon Nov 4, 2021
The documentation has been fixed. I believe that the trend towards I/O protocols means that this issue is basically resolved.