[issue45899] NameError on if clause of class-level list comprehension

2021-11-25 Thread Matthew Barnett
Matthew Barnett added the comment: It's not just in the 'if' clause: >>> class Foo: ... a = ['a', 'b'] ... b = ['b', 'c'] ... c = [b for x in a] ... Traceback (most recent call last): File "", line 1, in File "", line 4, in Foo File "", line 4, in NameError: name 'b' is

[issue45899] NameError on if clause of class-level list comprehension

2021-11-25 Thread Mark Dickinson
Mark Dickinson added the comment: This is expected behaviour. See the docs here: https://docs.python.org/3.9/reference/executionmodel.html#resolution-of-names > The scope of names defined in a class block is limited to the class block; it > does not extend to the code blocks of methods –

[issue45899] NameError on if clause of class-level list comprehension

2021-11-25 Thread ThiefMaster
Change by ThiefMaster : -- nosy: +ThiefMaster ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue45899] NameError on if clause of class-level list comprehension

2021-11-25 Thread jhpfjyne
New submission from jhpfjyne : Accessing an attribute defined at class-level in the if clause of a list comprehension at class-level throws a NameError. >>> class Foo: ... a = ['a', 'b'] ... b = ['b', 'c'] ... c = [x for x in a if x not in b] ... Traceback (most recent call last):