I'm running on Python 2.7.8 (Anaconda Distribution) and this code fails. This looks like a bug in the Python implementation, but am I missing anything?
class C:
x = {2 : 1}
y = {w for w in x if x[w]==1}
Running this code gives the following error message:
NameError: global name 'x' is not defined
The error message also seems wrong to me.
Note that the following two very similar pieces of code do work with no problems:
# this works fine:
class C:
x = {2 : 1}
y = [w for w in x if x[w]==1]
# this works fine too:
x = {2 : 1}
y = {w for w in x if x[w]==1}