python / python/cpython

Update FileIO comments, documentation to match implementation

Aperta
#129,011 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

docs
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Documentation

Discuss thread: https://discuss.python.org/t/change-open-write-to-guarantee-all-bytes-will-be-written-or-an-exception-will-be-thrown/71082

  1. FileIO behaves differently than its code comments around read and readall. Update the code comments to match current behavior
    • PEP 475, reads are retried in some cases
    • .readall() makes multiple system calls by design
  2. Add documentation to open() builtin that buffering=0, which currently just says "disables buffering") changes how .write() behaves and may result in data loss as a result of a partial write (ex. gh-126606).
    • TextIO and BufferedIO (which are gotten via commonly used open('README.rst'), open('README.rst', 'rb')) retry partial writes providing a user a guarantee either all bytes will be written or an exception will be thrown.
    • FileIO is "Raw I/O" and by PEP-3116 design, as documented, and currently implemented does not retry partial writes.
    • Most the time, buffering=0 currently speeds up writing a file, but it can also result in corrupted files, ex. gh-126606 from using FileIO directly
    • I would like to try and change the behavior of buffering=0 to use BufferedIO but with a 0 sized buffer, and that is on my roadmap but will be a while (people use the flag for a reason / get benefit!). This will mean open() always returns an object which implements "Write all or throw exception" behavior.
    • Add warning / document existing behavior on open() in the meantime.
Linked PRs
  • gh-129012
  • gh-135328
  • gh-150957
  • gh-150958
  • gh-150959

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia esaminando i commenti nel codice di FileIO e la documentazione del builtin open() collegata nell’issue, quindi analizza le PR collegate gh-129012, gh-135328, gh-150957, gh-150958 e gh-150959. Il lavoro è completato quando i commenti descrivono il comportamento attuale di read/readall e la documentazione di open() spiega chiaramente buffering=0 e il comportamento relativo alla perdita di dati nelle scritture parziali.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
documentation
Tipo di issue
Documentazione
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.