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

jhpfjyne report at bugs.python.org
Thu Nov 25 10:16:34 EST 2021


New submission from jhpfjyne <jhpfjyne at sharklasers.com>:

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):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in Foo
  File "<stdin>", line 4, in <listcomp>
NameError: name 'b' is not defined

----------
components: Interpreter Core
messages: 407002
nosy: jhpfjyne
priority: normal
severity: normal
status: open
title: NameError on if clause of class-level list comprehension
type: behavior
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45899>
_______________________________________


More information about the New-bugs-announce mailing list