From 2d2673f61386672f3971fc76bb0f03c05ec0ece2 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 26 Jul 2023 14:55:05 -0500 Subject: [PATCH] Add comment regarding class scope short circuit (#6101) --- crates/ruff_python_semantic/src/model.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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; }