[issue41918] exec fails to take locals into account when running list comprehensions or functions

Quentin Peter report at bugs.python.org
Wed Oct 14 09:33:59 EDT 2020


Quentin Peter <qpeter at bluewin.ch> added the comment:

Fails for functions as well:
```
In [4]: exec(compile('print(my_var)\ndef a():\n print(my_var)\na()', '<stdin>', 'exec'), globals(), {"my_var": 0})
0
Traceback (most recent call last):

File "<ipython-input-4-f091e49f2781>", line 1, in <module>
exec(compile('print(my_var)\ndef a():\n print(my_var)\na()', '<stdin>', 'exec'), globals(), {"my_var": 0})

File "<stdin>", line 4, in <module>

 File "<stdin>", line 3, in a

NameError: name 'my_var' is not defined
```

----------
title: exec fails to take locals into account when running list comprehensions -> exec fails to take locals into account when running list comprehensions or functions

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41918>
_______________________________________


More information about the Python-bugs-list mailing list