◐ Shell
clean mode source ↗

Message 324156 - Python tracker

This code:
class A:
    a = 1
    b = {str(x): x for x in range(5) if x != a}

Produces following error:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 3, in A
  File "<input>", line 3, in <dictcomp>
NameError: name 'a' is not defined


Which i think it shouldn't produce. Issue occurs only in dict comprehensions inside class definitions referencing class attributes(which are in local scope during definition).