Skip to content

Commit 0d44146

Browse files
committed
fix error that tuple with star expr
1 parent 2c8d76e commit 0d44146

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

mypy/checker.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,8 +2483,17 @@ def check_assignment_to_multiple_lvalues(self, lvalues: List[Lvalue], rvalue: Ex
24832483
# control in cases like: a, b = [int, str] where rhs would get
24842484
# type List[object]
24852485

2486-
rvalues = rvalue.items
2487-
2486+
rvalues = [] # type: List[Expression]
2487+
for rval in rvalue.items:
2488+
if isinstance(rval, StarExpr):
2489+
typs = self.expr_checker.visit_star_expr(rval)
2490+
typs = get_proper_type(typs.type)
2491+
if isinstance(typs, TupleType):
2492+
rvalues.extend([TempNode(typ) for typ in typs.items])
2493+
else:
2494+
rvalues.append(TempNode(typ))
2495+
else:
2496+
rvalues.append(rval)
24882497
if self.check_rvalue_count_in_assignment(lvalues, len(rvalues), context):
24892498
star_index = next((i for i, lv in enumerate(lvalues) if
24902499
isinstance(lv, StarExpr)), len(lvalues))

test-data/unit/check-tuples.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,3 +1421,10 @@ t6: Tuple[int, int, int, int, int, int, int, int, int, int, int, int] = (1, 2, 3
14211421
# E: Incompatible types in assignment (expression has type Tuple[int, int, ... <15 more items>], variable has type Tuple[int, int, ... <10 more items>])
14221422

14231423
[builtins fixtures/tuple.pyi]
1424+
1425+
[case testTupleWithStarExpr]
1426+
from typing import Tuple
1427+
points1 = (1, 2) # type: Tuple[int, int]
1428+
x, y, z = *points1, 0
1429+
1430+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)