Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,8 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> Type:
if len(s.lvalues) > 1:
# Chained assignment (e.g. x = y = ...).
# Make sure that rvalue type will not be reinferred.
if s.rvalue not in self.type_map:
self.accept(s.rvalue)
rvalue = self.temp_node(self.type_map[s.rvalue], s)
for lv in s.lvalues[:-1]:
self.check_assignment(lv, rvalue, s.type is None)
Expand Down
6 changes: 6 additions & 0 deletions mypy/test/data/check-tuples.test
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ b = ''
a = '' # E: Incompatible types in assignment (expression has type "str", variable has type "int")
b = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "str")

[case testMultipleAssignmentWithMixedVariables]
a = b, c = 1, 1
x, y = p, q = 1, 1
u, v, w = r, s = 1, 1 # E: Need more than 2 values to unpack (3 expected)
d, e = f, g, h = 1, 1 # E: Need more than 2 values to unpack (3 expected)


-- Assignment to starred expressions
-- ---------------------------------
Expand Down