[New-bugs-announce] [issue3692] improper scope in list comprehension, when used in class declaration

kai zhu report at bugs.python.org
Wed Aug 27 01:20:14 CEST 2008


New submission from kai zhu <davidbranniganz at gmail.com>:

in 3rd line, list comprehension tries to access class_attribute1 as a
global variable (code is valid in python 2.5)

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

----------
components: Interpreter Core
messages: 72002
nosy: kaizhu
severity: normal
status: open
title: improper scope in list comprehension, when used in class declaration
type: behavior
versions: Python 3.0

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


More information about the New-bugs-announce mailing list