New submission from Quentin Peter <qpe...@bluewin.ch>:
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 ---------- messages: 377862 nosy: qpeter priority: normal severity: normal status: open title: exec fails to take locals into account when running list comprehensions type: enhancement versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue41918> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com