Opaque type for io.TextIOWrapper seek and tell?
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 5.1k
- Fork
- 2.1k
- Merge medio
- 1g 19h
- PR unite (30g)
- 82
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia esaminando le annotazioni di io.TextIOWrapper seek() e tell() in typeshed insieme alla documentazione Python citata nell’issue. Una modifica completa rappresenterebbe i risultati di tell() come valori opachi e impedirebbe a seek() di accettare offset arbitrari, continuando tuttavia a consentire 0 e un valore restituito da tell().
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100