[Python-checkins] cpython: Fix a ResourceWarning in generate_opcode_h.py
victor.stinner
python-checkins at python.org
Fri Nov 25 06:00:26 EST 2016
https://hg.python.org/cpython/rev/46e2755b022c
changeset: 105360:46e2755b022c
user: Victor Stinner <victor.stinner at gmail.com>
date: Fri Nov 25 11:59:52 2016 +0100
summary:
Fix a ResourceWarning in generate_opcode_h.py
Use a context manager to close the Python file. Replace also open() with
tokenize.open() to handle coding cookie if any in Lib/opcode.py.
files:
Tools/scripts/generate_opcode_h.py | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/Tools/scripts/generate_opcode_h.py b/Tools/scripts/generate_opcode_h.py
--- a/Tools/scripts/generate_opcode_h.py
+++ b/Tools/scripts/generate_opcode_h.py
@@ -32,10 +32,14 @@
#endif /* !Py_OPCODE_H */
"""
+import tokenize
+
def main(opcode_py, outfile='Include/opcode.h'):
opcode = {}
- exec(open(opcode_py).read(), opcode)
+ with tokenize.open(opcode_py) as fp:
+ code = fp.read()
+ exec(code, opcode)
opmap = opcode['opmap']
with open(outfile, 'w') as fobj:
fobj.write(header)
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list