Bug report
Bug description:
typeing.BinaryIO is completely missing the readinto method. All binary mode return values of open support the readinto method, and the lack of it on the BinaryIO type makes type-hinting difficult when using this method. One could try to use io.RawIOBase | io.BufferedIOBase but this looses the fact that the result of open has a name property. This has been brought up in python/typing#659 and python/typeshed#2166.
Furthmore, the write method in BinaryIO is declared to only be compatible with Union[bytes, bytearray] when it should be anything that satisfies collections.abc.Buffer.
I propose that BinaryIO should look something more like:
class BinaryIO(IO[bytes]):
"""Typed version of the return of open() in binary mode."""
__slots__ = ()
@abstractmethod
def readinto(self, b: collections.abc.Buffer) -> int:
pass
@abstractmethod
def write(self, s: collections.abc.Buffer) -> int:
pass
@abstractmethod
def __enter__(self) -> 'BinaryIO':
pass
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
Bug report
Bug description:
typeing.BinaryIOis completely missing thereadintomethod. All binary mode return values ofopensupport thereadintomethod, and the lack of it on theBinaryIOtype makes type-hinting difficult when using this method. One could try to useio.RawIOBase | io.BufferedIOBasebut this looses the fact that the result ofopenhas anameproperty. This has been brought up in python/typing#659 and python/typeshed#2166.Furthmore, the
writemethod inBinaryIOis declared to only be compatible withUnion[bytes, bytearray]when it should be anything that satisfiescollections.abc.Buffer.I propose that BinaryIO should look something more like:
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs