Opaque type for io.TextIOWrapper seek and tell?
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 5.1k
- Forks
- 2.1k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 82
Beschreibung
The following prints 18446744073709551620 (as I discovered in https://github.com/python/cpython/issues/93077):
import io
stream = io.TextIOWrapper(io.BytesIO(b'"")\r\nx\r\n'))
stream.read(1)
stream.read(1)
stream.read(1)
print('-----> tell:', stream.tell())
This is not a bug. The documentation says that .tell() returns "an opaque number" that "does not usually represent a number of bytes in the underlying binary storage".
In fact, calling .seek() with anything else than 0 or a return value of .tell() "produces undefined behaviour". I just relied on that today, without knowing it. I wrote this code:
def _upgrade_high_scores_file(file: IO[str], old_version: int) -> None:
...
file.seek(len(b"catris high scores file v"))
...
This shouldn't pass the type check IMO.
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
Beginne damit, die Annotationen von io.TextIOWrapper seek() und tell() in typeshed zusammen mit der im Issue zitierten Python-Dokumentation zu prüfen. Eine vollständige Änderung würde die Ergebnisse von tell() als opake Werte darstellen und verhindern, dass seek() beliebige Offsets akzeptiert, während 0 und ein von tell() zurückgegebener Wert weiterhin zulässig sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100