[issue13332] execfile fixer produces code that does not close the file

Sven Marnach report at bugs.python.org
Thu Nov 3 18:34:48 CET 2011


Sven Marnach <sven at marnach.net> added the comment:

Getting the general case right seems a bit too difficult.  Examples like

    [execfile(n) for n in names if condition(n)]

    execfile(execfile(n1) or n2)

    try: 1 / 0
    except execfile(n) or ZeroDivisionError: pass

would require rather complex transformations to get exactly matching behaviour, and obviously we don't want to explode the fixer code to support such nonsense.

I think it is enough to cover the case of an execfile() call that forms a statement of its own.  Browsing through the first ten pages of a Google code search for "execfile" didn't reveal any other uses, except for a few that aren't covered by the current version of the fixer either. [1]

I'd suggest to simply throw a "could not convert" warning for any other uses of execfile().  Opinions?

[1]: http://www.google.com/codesearch#yqvQ9RM69FY/mercurial/lsprof.py&q=execfile&sq=&l=111&ct=rc&cd=49

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13332>
_______________________________________


More information about the Python-bugs-list mailing list