Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Apr 13, 2026
commit e98f4be03f44786f695672a58697dc11704c7f57
6 changes: 2 additions & 4 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2110,9 +2110,7 @@ def analyze_class_body_common(self, defn: ClassDef) -> None:
# Pre-scan class body to find names assigned at class scope level.
# This must happen after enter_class (which pushes an empty set) so we
# can replace it with the real set.
self.class_body_assigned_names[-1] = collect_class_body_assigned_names(
defn.defs.body
)
self.class_body_assigned_names[-1] = collect_class_body_assigned_names(defn.defs.body)
if any(b.self_type is not None for b in defn.info.mro):
self.setup_self_type()
defn.defs.accept(self)
Expand Down Expand Up @@ -8396,7 +8394,7 @@ def collect_class_body_assigned_names(stmts: list[Statement]) -> set[str]:
This mirrors CPython's compile-time analysis that determines whether a name
in a class body is accessed via LOAD_NAME (class dict -> globals -> builtins)
or LOAD_CLASSDEREF or LOAD_FROM_DICT_OR_DEREF (class dict -> enclosing function cell).

Names that are assigned anywhere in the class body (even inside if/for/while/try/with blocks)
use LOAD_NAME, so they should NOT be resolved from enclosing function locals.

Expand Down
Loading