Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
Open
Description
Bug report
Bug description:
typeing.BinaryIO
is completely missing thereadinto
method. All binary mode return values ofopen
support thereadinto
method, and the lack of it on theBinaryIO
type makes type-hinting difficult when using this method. One could try to useio.RawIOBase | io.BufferedIOBase
but this looses the fact that the result ofopen
has aname
property. This has been brought up inpython/typing#659 andpython/typeshed#2166.
Furthmore, thewrite
method inBinaryIO
is 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:
classBinaryIO(IO[bytes]):"""Typed version of the return of open() in binary mode."""__slots__= ()@abstractmethoddefreadinto(self,b:collections.abc.Buffer)->int:pass@abstractmethoddefwrite(self,s:collections.abc.Buffer)->int:pass@abstractmethoddef__enter__(self)->'BinaryIO':pass
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response