diff --git a/crates/ruff_python_semantic/src/model.rs b/crates/ruff_python_semantic/src/model.rs index 1c52a856c3..b316249fb3 100644 --- a/crates/ruff_python_semantic/src/model.rs +++ b/crates/ruff_python_semantic/src/model.rs @@ -313,6 +313,20 @@ impl<'a> SemanticModel<'a> { if seen_function && matches!(symbol, "__class__") { return ReadResult::ImplicitGlobal; } + // Do not allow usages of class symbols unless it is the immediate parent, e.g.: + // + // ```python + // class Foo: + // a = 0 + // + // b = a # allowed + // def c(self, arg=a): # allowed + // print(arg) + // + // def d(self): + // print(a) # not allowed + // ``` + // if index > 0 { continue; }