New submission from Ariel Bruner: The following code gives a NameError:
>>> def foo(bar): print {eval(x) for x in ['bar']} >>> foo(2) Traceback (most recent call last): File "<pyshell#52>", line 1, in <module> foo(2) File "<pyshell#51>", line 2, in foo print {eval(x) for x in ['bar']} File "<pyshell#51>", line 2, in <setcomp> print {eval(x) for x in ['bar']} File "<string>", line 1, in <module> NameError: name 'bar' is not defined I've seen this kind of bug reported for Python 3.X (e.g. Issue5242), and the behavior seems to be identical (e.g. can be fixed with {eval(x) for x in ['bar'] if True or bar}), but the previously reported bug reports mention comprehension is implemented differently on 2.X and that it should not happen there, so I thought that might be of interest. ---------- components: Windows messages: 238561 nosy: Ariel Bruner, steve.dower, tim.golden, zach.ware priority: normal severity: normal status: open title: Comprehension + eval doesn't work inside function definition versions: Python 2.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue23714> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com