Vedran Čačić added the comment:

List comprehension is irrelevant here, any nested function has the same 
problem. And the inner name doesn't have to refer to a function. Also, 
compilation as a separate step is not necessary.

So the minimal example is

    src = '''\
    a = 5
    def g(x): return a + x
    print(g(3))
    '''
    def comp(): exec(src)
    comp()

But I'm not sure if it is a bug at all. If you write explicitly

    exec(src, {})

you get a result 8 without problem. The docs say

    ...if the optional parts are omitted, the code is executed in the current 
scope.

And the current scope inside comp is "fast locals", where you can't really make 
new names. Maybe exec should raise an exception then, but it surely cannot just 
"work" inside fast locals scope.

----------
nosy: +veky

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31401>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to