This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author qpeter
Recipients qpeter
Date 2020-10-03.09:06:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1601716004.0.0.802801393199.issue41918@roundup.psfhosted.org>
In-reply-to
Content
The exec function fails to take locals into account when executing a list comprehension:
```
Python 3.7.7 (default, Mar 10 2020, 15:43:33) 
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exec(compile('[my_var for i in range(1)]\n', '<stdin>', 'single'), {**globals(), "my_var": 0}, None)
[0]
>>> exec(compile('[my_var for i in range(1)]\n', '<stdin>', 'single'), globals(), {"my_var": 0})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <listcomp>
NameError: name 'my_var' is not defined
>>> 
```
This is the cause of https://bugs.python.org/issue21161
History
Date User Action Args
2020-10-03 09:06:44qpetersetrecipients: + qpeter
2020-10-03 09:06:44qpetersetmessageid: <1601716004.0.0.802801393199.issue41918@roundup.psfhosted.org>
2020-10-03 09:06:43qpeterlinkissue41918 messages
2020-10-03 09:06:43qpetercreate