[issue24800] Incorrect handling of local variables in comprehensions with exec()

R. David Murray report at bugs.python.org
Wed Aug 5 22:42:01 CEST 2015


R. David Murray added the comment:

Yes it is.  The comprehension is a *new* scope, within the outer scope of the exec, and it *cannot see* the variables in the outer scope of the exec.  You have the same problem if you try to use a comprehension in that way in a class statement at the class level.  An exec is explicitly *not* equivalent to a function body.  It is equivalent to operating in a class body, if you give it two namespaces, and in a global context if you give it one.  This is documented.

Please don't reopen the issue.

----------
resolution:  -> not a bug
status: open -> closed

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


More information about the Python-bugs-list mailing list