Message301794
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. |
|
Date |
User |
Action |
Args |
2017-09-09 23:14:34 | veky | set | recipients:
+ veky, r.david.murray, jpc |
2017-09-09 23:14:34 | veky | set | messageid: <1504998874.87.0.513220052881.issue31401@psf.upfronthosting.co.za> |
2017-09-09 23:14:34 | veky | link | issue31401 messages |
2017-09-09 23:14:34 | veky | create | |
|