This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author conchylicultor
Recipients conchylicultor
Date 2020-11-30.11:17:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1606735074.2.0.265647933695.issue42512@roundup.psfhosted.org>
In-reply-to
Content
Currently, because `BinaryIO` is subclass of `IO[bytes]`, the 2 cannot be used interchangeably.

Example with pytype:

```
def iter_zip(arch_f) -> List[typing.BinaryIO]]:
  with open(arch_f, 'rb') as fobj:
    z = zipfile.ZipFile(fobj)
    return [z.open(member) for member in z.infolist()]
```

Raise:

```
           Expected: Tuple[str, BinaryIO]
  Actually returned: Tuple[Any, IO[bytes]]
```

Technically pytype is right as `ZipFile.open() -> IO[bytes]`:

https://github.com/python/typeshed/blob/ca45cb21a8a0422cbb266cb25e08051fe481887c/stdlib/2and3/zipfile.pyi#L109

But this makes BinaryIO usage quite confusing.

From the implementation, it seems that the BinaryIO is slightly different (https://github.com/python/cpython/blob/9f004634a2bf50c782e223e2eb386ffa769b901c/Lib/typing.py#L2094):

But the documentation is unclear about the difference between the 2 https://docs.python.org/3/library/typing.html#typing.BinaryIO


Additionally, `typing.IO` is implemented as Generic but shouldn't this be a Protocol instead ?
History
Date User Action Args
2020-11-30 11:17:54conchylicultorsetrecipients: + conchylicultor
2020-11-30 11:17:54conchylicultorsetmessageid: <1606735074.2.0.265647933695.issue42512@roundup.psfhosted.org>
2020-11-30 11:17:54conchylicultorlinkissue42512 messages
2020-11-30 11:17:53conchylicultorcreate