Skip to content

Commit bc8a3ad

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

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

mypy/checker.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,8 +2483,16 @@ 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 = get_proper_type(self.expr_checker.visit_star_expr(rval).type)
2490+
if isinstance(typs, TupleType):
2491+
rvalues.extend([TempNode(typ) for typ in typs.items])
2492+
else:
2493+
rvalues.append(TempNode(typs))
2494+
else:
2495+
rvalues.append(rval)
24882496
if self.check_rvalue_count_in_assignment(lvalues, len(rvalues), context):
24892497
star_index = next((i for i, lv in enumerate(lvalues) if
24902498
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+
points = (1, 2) # type: Tuple[int, int]
1428+
x, y, z = *points, 0
1429+
1430+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)