Skip to content

Commit 111a3c4

Browse files
committed
Fix assignment to __class__ check to use errors.report() in VarAssignVisitor (Fixes #7724)
Replaces previous incorrect call to self.chk.fail() with self.errors.report(), resolving AttributeError. Ensures assignment to __class__ is properly reported as an error during instance attribute assignments.
1 parent fe381b2 commit 111a3c4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

mypy/checker.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8882,7 +8882,11 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
88828882
lv.accept(self)
88838883
if isinstance(lv, MemberExpr):
88848884
if lv.name == '__class__':
8885-
self.chk.fail("Assignment to '__class__' is unsafe and not allowed", lv)
8885+
self.errors.report(
8886+
lv.line,
8887+
lv.column,
8888+
"Assignment to '__class__' is unsafe and not allowed"
8889+
)
88868890
self.lvalue = False
88878891

88888892
def visit_name_expr(self, e: NameExpr) -> None:

0 commit comments

Comments
 (0)