"typing.BinaryIO" missing "readinto" method
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie bei der Definition von typing.BinaryIO und vergleichen Sie sie mit den Rückgabewerten von open() im Binärmodus, wobei Sie sich auf die vorgeschlagenen readinto- und Buffer-kompatiblen write-Signaturen konzentrieren. Überprüfen Sie, dass BinaryIO weiterhin die name-Eigenschaft bereitstellt und dass das aktualisierte Verhalten von typing durch die relevanten bestehenden Tests abgedeckt ist; das Issue nennt keine bestimmte Datei oder keinen bestimmten Test.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- developer-experience
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100