Skip to content
Draft
Changes from all commits
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
21 changes: 3 additions & 18 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3175,7 +3175,7 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
# as X | Y.
if not (s.is_alias_def and self.is_stub):
with self.enter_final_context(s.is_final_def):
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None)

if s.is_alias_def:
self.check_type_alias_rvalue(s)
Expand Down Expand Up @@ -3223,11 +3223,7 @@ def check_type_alias_rvalue(self, s: AssignmentStmt) -> None:
self.store_type(s.lvalues[-1], alias_type)

def check_assignment(
self,
lvalue: Lvalue,
rvalue: Expression,
infer_lvalue_type: bool = True,
new_syntax: bool = False,
self, lvalue: Lvalue, rvalue: Expression, infer_lvalue_type: bool = True
) -> None:
"""Type check a single assignment: lvalue = rvalue."""
if isinstance(lvalue, (TupleExpr, ListExpr)):
Expand Down Expand Up @@ -3295,15 +3291,6 @@ def check_assignment(
# Try to infer a partial type. No need to check the return value, as
# an error will be reported elsewhere.
self.infer_partial_type(lvalue_type.var, lvalue, rvalue_type)
elif (
is_literal_none(rvalue)
and isinstance(lvalue, NameExpr)
and isinstance(lvalue.node, Var)
and lvalue.node.is_initialized_in_class
and not new_syntax
):
# Allow None's to be assigned to class variables with non-Optional types.
rvalue_type = lvalue_type
elif (
isinstance(lvalue, MemberExpr) and lvalue.kind is None
): # Ignore member access to modules
Expand Down Expand Up @@ -5056,9 +5043,7 @@ def visit_operator_assignment_stmt(self, s: OperatorAssignmentStmt) -> None:
# There is no __ifoo__, treat as x = x <foo> y
expr = OpExpr(s.op, s.lvalue, s.rvalue)
expr.set_line(s)
self.check_assignment(
lvalue=s.lvalue, rvalue=expr, infer_lvalue_type=True, new_syntax=False
)
self.check_assignment(lvalue=s.lvalue, rvalue=expr, infer_lvalue_type=True)
self.check_final(s)

def visit_assert_stmt(self, s: AssertStmt) -> None:
Expand Down
Loading