Skip to content

Commit 6149465

Browse files
committed
Use BufferedWriter's loop to write .pyc files
1 parent 914caf1 commit 6149465

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

Lib/importlib/_bootstrap_external.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,8 @@ def _write_atomic(path, data, mode=0o666):
208208
try:
209209
# We first write data to a temporary file, and then use os.replace() to
210210
# perform an atomic rename.
211-
with _io.FileIO(fd, 'wb') as file:
212-
bytes_written = 0
213-
while bytes_written < len(data):
214-
last_bytes_written = file.write(data[bytes_written:])
215-
bytes_written += last_bytes_written
216-
if last_bytes_written < 1:
217-
raise OSError("os.write() didn't write the full pyc file")
211+
with _io.FileIO(fd, 'wb') as file, _io.BufferedWriter(file) as writer:
212+
writer.write(data)
218213
_os.replace(path_tmp, path)
219214
except OSError:
220215
try:

0 commit comments

Comments
 (0)