Write rewritten code using file.write(marshal.dumps())

This works around the fact that some libraries might monkey patch
the file object, so the previous approach of marshal.dump(co, file)
breaks because file is not a built-in file object anymore.

Fix #3503
This commit is contained in:
Bruno Oliveira 2018-05-25 17:24:23 -03:00
parent 65bc43dc56
commit b5a94d8e6c
2 changed files with 2 additions and 4 deletions

View File

@ -265,10 +265,7 @@ def _write_pyc(state, co, source_stat, pyc):
mtime = int(source_stat.mtime)
size = source_stat.size & 0xFFFFFFFF
fp.write(struct.pack("<ll", mtime, size))
if six.PY2:
marshal.dump(co, fp.file)
else:
marshal.dump(co, fp)
fp.write(marshal.dumps(co))
except EnvironmentError as e:
state.trace("error writing pyc file at %s: errno=%s" % (pyc, e.errno))
# we ignore any failure to write the cache file

View File

@ -0,0 +1 @@
Fix assertion rewriter compatibility with libraries that monkey patch ``file`` objects.