Open
Description
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
- FileIO behaves differently than its code comments around
read
andreadall
. Update the code comments to match current behavior- PEP 475, reads are retried in some cases
.readall()
makes multiple system calls by design
- Add documentation to
open()
builtin thatbuffering=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. Corrupt .pyc files stay on disk after failed writes #126606).TextIO
andBufferedIO
(which are gotten via commonly usedopen('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. Corrupt .pyc files stay on disk after failed writes #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 meanopen()
always returns an object which implements "Write all or throw exception" behavior. - Add warning / document existing behavior on
open()
in the meantime.