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.

classification
Title: Local variables unavailable for operation of list comprehension when using eval()
Type: Stage:
Components: Versions: Python 3.0, Python 3.1
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, evan.greensmith
Priority: normal Keywords:

Created on 2009-03-20 03:59 by evan.greensmith, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_eval_comp.py evan.greensmith, 2009-03-20 03:59 Tests of eval containing comprehensions
Messages (2)
msg83852 - (view) Author: Evan Greensmith (evan.greensmith) Date: 2009-03-20 03:59
In python 3.0 and 3.1, attempting to access a local variable from within
a list comprehension in a string passed to eval() causes a NameError. 
Doesn't seem to be a problem in python 2.6

I have attempted to run the attached test cases (test_eval_comp.py)
using the following builds of python:

Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit
(Intel)] on win32

Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit
(Intel)] on win32

Python 3.1a1 (r31a1:70244, Mar  8 2009, 18:15:03) [MSC v.1500 32 bit
(Intel)] on win32

All tests passed with Python 2.6.1.  The following five tests failed
with Python 3.0.1 and 3.1a1

EvalWithComprehensionTestCase.test_local_var
    NameError: global name 'value' is not defined
EvalWithComprehensionTestCase.test_function_arg
    NameError: global name 'value' is not defined
EvalWithComprehensionTestCase.test_self_attrib
    NameError: global name 'self' is not defined
ExampleFromDocsTestCase.test_local_var
    NameError: global name 'vec1' is not defined
NestedComprehensionExampleFromDocsTestCase.test_local_var
    NameError: global name 'mat' is not defined
msg83859 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-03-20 11:46
This is a fundamental limitation of how comprehensions are implemented
in Python 3 and is unlikely to change anytime soon.
History
Date User Action Args
2022-04-11 14:56:46adminsetgithub: 49776
2009-03-20 11:46:50benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg83859

resolution: wont fix
2009-03-20 03:59:27evan.greensmithcreate