diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-11-25 10:59:52 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-11-25 10:59:52 (GMT) |
commit | 6193ecd77907dafa83235dd1386354613ecafcdf (patch) | |
tree | e6a09691ac88d2831e3bea5b794f24ef33209ce8 /Tools/scripts | |
parent | 1018fad6a4df3d7fcb0ec715867069044428a759 (diff) | |
download | cpython-6193ecd77907dafa83235dd1386354613ecafcdf.zip cpython-6193ecd77907dafa83235dd1386354613ecafcdf.tar.gz cpython-6193ecd77907dafa83235dd1386354613ecafcdf.tar.bz2 |
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.
Diffstat (limited to 'Tools/scripts')
-rw-r--r-- | 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 index 948b56f..bbc3aab 100644 --- a/Tools/scripts/generate_opcode_h.py +++ b/Tools/scripts/generate_opcode_h.py @@ -32,10 +32,14 @@ enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE, #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) |