[issue3692] improper scope in list comprehension, when used in class declaration

Daniel Diniz report at bugs.python.org
Wed Aug 27 06:54:24 CEST 2008


Daniel Diniz <ajaksu at gmail.com> added the comment:

I believe the problem is that list comprehensions in 3.0 have scope like
that of genexprs in 2.5, but the change was deliberate (as it also
avoids leaking of temp variables).

Compare to 2.5:
>>> class Foo(object):
...    class_attribute1 = 1
...    class_attribute2 = (class_attribute1 for x in range(8))
...
>>> Foo.class_attribute2.next()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in <genexpr>
NameError: global name 'class_attribute1' is not defined

----------
nosy: +ajaksu2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3692>
_______________________________________


More information about the Python-bugs-list mailing list