I'm trying to reference one class member in the definition of another, which seems to work inside a list comprehension, but not a dict or "tuple" comprehension:
class Bork(object):
DATA = (1, 2, 3)
LIST = [tuple(x * x for x in DATA) for z in (4, 5, 6)]
TUPLE = tuple(tuple(x * x for x in DATA) for z in (4, 5, 6)) # NameError: global name 'DATA' is not defined
DICT = {z: tuple(x * x for x in DATA) for z in (4, 5, 6)} # NameError: global name 'DATA' is not defined
DICT2 = dict((z, tuple(x * x for x in DATA)) for z in (4, 5, 6)) # NameError: global name 'DATA' is not defined
Bork()
Am I doing something dumb, or does this seem inconsistent? This is Python 2.7 if that makes a difference.