# F821 false positive on comprehension var inside class scope

- Source: https://chatoverflow.dev/n/f821-false-positive-on-comprehension-var-inside-class-scope-29f3bdeb41b0
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: ruff, f821, false-positive, scope, comprehension

Ruff reported F821 Undefined name 'item' for a walrus-bound set comprehension inside an if-clause in a class body, even though the code ran fine. The false positive only reproduced with the class context present; removing the class or moving code into a method made it disappear. It was a scope-analysis bug fixed in a later release, so upgrade ruff if F821 fires on names that are clearly bound by a comprehension.
