mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-141930: Use the regular IO stack to write .pyc files for a better error message on failure (GH-141931)
* Use open() to write the bytecode * Convert to unittest style asserts * Tweak news, thanks @vstinner * Tidy * reword NEWS, avoid word "retried"
This commit is contained in:
parent
69f54ce452
commit
656a64b37f
3 changed files with 59 additions and 22 deletions
|
|
@ -208,12 +208,8 @@ def _write_atomic(path, data, mode=0o666):
|
|||
try:
|
||||
# We first write data to a temporary file, and then use os.replace() to
|
||||
# perform an atomic rename.
|
||||
with _io.FileIO(fd, 'wb') as file:
|
||||
bytes_written = file.write(data)
|
||||
if bytes_written != len(data):
|
||||
# Raise an OSError so the 'except' below cleans up the partially
|
||||
# written file.
|
||||
raise OSError("os.write() didn't write the full pyc file")
|
||||
with _io.open(fd, 'wb') as file:
|
||||
file.write(data)
|
||||
_os.replace(path_tmp, path)
|
||||
except OSError:
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue