@@ -2482,17 +2482,38 @@ def check_assignment_to_multiple_lvalues(self, lvalues: List[Lvalue], rvalue: Ex
2482
2482
# using the type of rhs, because this allowed more fine grained
2483
2483
# control in cases like: a, b = [int, str] where rhs would get
2484
2484
# type List[object]
2485
-
2486
2485
rvalues = [] # type: List[Expression]
2486
+ lhs_len = len (lvalues )
2487
+ idx_of_iterable = []
2488
+ item_type_of_iterable = [] # type: List['mypy.types.Type']
2489
+ idx = 0
2487
2490
for rval in rvalue .items :
2488
2491
if isinstance (rval , StarExpr ):
2489
- typs = get_proper_type (self .expr_checker .visit_star_expr (rval ).type )
2492
+ typs = get_proper_type (self .expr_checker .visit_star_expr (rval ).type ) # type: ProperType
2490
2493
if isinstance (typs , TupleType ):
2491
2494
rvalues .extend ([TempNode (typ ) for typ in typs .items ])
2495
+ lhs_len -= len (typs .items )
2496
+ idx += len (typs .items )
2497
+ elif self .type_is_iterable (typs ):
2498
+ item_type_of_iterable .append (self .iterable_item_type (typs ))
2499
+ idx_of_iterable .append (idx )
2492
2500
else :
2493
- rvalues . append ( TempNode (typs ))
2501
+ self . fail ( "StarExpr should not be a '{}'" . format (typs ), context )
2494
2502
else :
2495
2503
rvalues .append (rval )
2504
+ lhs_len -= 1
2505
+ idx += 1
2506
+ num_every_iterable = 0
2507
+ num_last_iterable = 0
2508
+ if len (idx_of_iterable ):
2509
+ num_every_iterable = int (lhs_len / len (idx_of_iterable ))
2510
+ num_last_iterable = lhs_len - (len (idx_of_iterable ) - 1 ) * int (num_every_iterable )
2511
+ for i , (idx , item_type ) in enumerate (zip (idx_of_iterable , item_type_of_iterable )):
2512
+ if i == (len (idx_of_iterable ) - 1 ):
2513
+ rvalues [idx :idx ] = [TempNode (item_type ) for _ in range (num_last_iterable )]
2514
+ else :
2515
+ rvalues [idx :idx ] = [TempNode (item_type ) for _ in range (num_every_iterable )]
2516
+
2496
2517
if self .check_rvalue_count_in_assignment (lvalues , len (rvalues ), context ):
2497
2518
star_index = next ((i for i , lv in enumerate (lvalues ) if
2498
2519
isinstance (lv , StarExpr )), len (lvalues ))
0 commit comments