Issue #17244: Don't mask exceptions raised during the creation of
bytecode files in py_compile.
Thanks to Arfrever Frehtes Taifersar Arahesis for the bug report.
diff --git a/Lib/py_compile.py b/Lib/py_compile.py
index d255a2d..701e8ac 100644
--- a/Lib/py_compile.py
+++ b/Lib/py_compile.py
@@ -106,7 +106,7 @@
source_bytes = loader.get_data(file)
try:
code = loader.source_to_code(source_bytes, dfile or file,
- _optimize=optimize)
+ _optimize=optimize)
except Exception as err:
py_exc = PyCompileError(err.__class__, err, dfile or file)
if doraise:
@@ -121,11 +121,13 @@
except FileExistsError:
pass
source_stats = loader.path_stats(file)
- bytecode = importlib._bootstrap._code_to_bytecode(code,
- source_stats['mtime'], len(source_bytes))
- loader._cache_bytecode(file, cfile, bytecode)
+ bytecode = importlib._bootstrap._code_to_bytecode(
+ code, source_stats['mtime'], source_stats['size'])
+ mode = importlib._bootstrap._calc_mode(file)
+ importlib._bootstrap._write_atomic(cfile, bytecode, mode)
return cfile
+
def main(args=None):
"""Compile several source files.