[New-bugs-announce] [issue13332] execfile fixer produces code that does not close the file
Sven Marnach
report at bugs.python.org
Thu Nov 3 13:11:32 CET 2011
New submission from Sven Marnach <sven at marnach.net>:
The execfile fixer of the 2to3 script replaces the 2.x code
execfile("a.py")
by
exec(compile(open("a.py").read(), "a.py", 'exec'))
The new code does not explicitly close the file. This is not usually a problem in CPython, but
1. the code will throw a RessourceWarnings if enabled and
2. other Python implementation don't close the file immediately.
(I think the 2to3 script should be as implementation-independent as possible.)
The obvious fix would be to use a with-statement:
with open("a.py") as new_name:
exec(compile(new_name.read(), "a.py", 'exec'))
If this is to be changed, I'd be happy to prepare a patch.
----------
components: 2to3 (2.x to 3.x conversion tool)
messages: 146918
nosy: smarnach
priority: normal
severity: normal
status: open
title: execfile fixer produces code that does not close the file
type: behavior
versions: Python 3.2, Python 3.3
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13332>
_______________________________________
More information about the New-bugs-announce
mailing list