Skip to content

TextIO/BinaryIO: Mismatch between documentation and implementation #518

Closed

Description

@srittau

The typing documentation for 3.6.4rc1 at states:

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.

See python/typeshed#1780 for a real-world example.

Activity

  1. gvanrossum commented on Dec 12, 2017

    @gvanrossum
    Member

    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?

  2. srittau commented on Dec 12, 2017

    @srittau
    CollaboratorAuthor

    @gvanrossum I filed it as bpo-32284, but someone else needs to set the blocker priority.

  3. srittau commented on Nov 4, 2021

    @srittau
    CollaboratorAuthor

    The documentation has been fixed. I believe that the trend towards I/O protocols means that this issue is basically resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions