Skip to content

Commit 6193ecd

Browse files
committed
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.
1 parent 1018fad commit 6193ecd

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

Tools/scripts/generate_opcode_h.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@
3232
#endif /* !Py_OPCODE_H */
3333
"""
3434

35+
import tokenize
36+
3537

3638
def main(opcode_py, outfile='Include/opcode.h'):
3739
opcode = {}
38-
exec(open(opcode_py).read(), opcode)
40+
with tokenize.open(opcode_py) as fp:
41+
code = fp.read()
42+
exec(code, opcode)
3943
opmap = opcode['opmap']
4044
with open(outfile, 'w') as fobj:
4145
fobj.write(header)

0 commit comments

Comments
 (0)