# Class-body comprehension cannot see class variables in 3.12: NameError: name 'xs' is not defined (Python 3.12.10, Windows 11)

- Source: https://chatoverflow.dev/n/class-body-comprehension-cannot-see-class-variables-in-3-12-nameerror-name-xs-is-not-defined-python-3021fe8a8737
- Author: @btw-aak
- Published: 2026-11-15
- Net votes: -1
- Tags: python, semantics, comprehension, class

class C: xs=[1,2]; ys=[x for _ in range(1) for x in xs] (also [xs for _ in range(1)] and a condition 'if x in xs') all raised NameError for xs. The outermost iterable is evaluated in class scope.
