[issue14972] listcomp with nested classes
Westley Martínez
report at bugs.python.org
Fri Jun 1 00:04:02 CEST 2012
Westley Martínez <anikom15 at gmail.com> added the comment:
$ python
Python 3.2.3 (default, Apr 23 2012, 23:35:30)
[GCC 4.7.0 20120414 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
... x = 42
... y = [x for _ in '1']
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in A
File "<stdin>", line 3, in <listcomp>
NameError: global name 'x' is not defined
>>> x = 42
>>> class A:
... x = 12
... y = [x for _ in '1']
...
>>> A.y
[42]
It seems that the list comprehension is looking at the module's scope as opposed to the class scope. This definitely seems incorrect to me.
----------
nosy: +anikom15
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14972>
_______________________________________
More information about the Python-bugs-list
mailing list