Skip to content

Commit fa70fc5

Browse files
committed
Avoid crash in edge case of multiple assignment. Fix #974, # 1420, #1438. (#1451)
1 parent 08ad739 commit fa70fc5

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

mypy/checker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,8 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> Type:
11431143
if len(s.lvalues) > 1:
11441144
# Chained assignment (e.g. x = y = ...).
11451145
# Make sure that rvalue type will not be reinferred.
1146+
if s.rvalue not in self.type_map:
1147+
self.accept(s.rvalue)
11461148
rvalue = self.temp_node(self.type_map[s.rvalue], s)
11471149
for lv in s.lvalues[:-1]:
11481150
self.check_assignment(lv, rvalue, s.type is None)

mypy/test/data/check-tuples.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,12 @@ b = ''
364364
a = '' # E: Incompatible types in assignment (expression has type "str", variable has type "int")
365365
b = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "str")
366366

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

368374
-- Assignment to starred expressions
369375
-- ---------------------------------

0 commit comments

Comments
 (0)