This seems like a really weird scoping issue:
First I'll show what works:
class A():
x = 1
y = x
class B():
x = {'a' : 1, 'b' : 2}
y = {z : 1 for z in x}
Does not work:
class C():
x = {'a' : 1, 'b' : 2}
y = {z : max(x) for z in x} # max could be replaced with any function
Leading to:
NameError: name 'x' is not defined
And I know it refers to the "inner" (value) in the dictionary comprehension.
This probably means that somehow in the list comprehension the class scope is not available.
How come, and how can we work around this (without using it as an instance variable, i.e. using __init__)?