Skip to content

Commit 8667022

Browse files
Fix missing error context for unpacking assignment involving star expression (#19258)
Fixes #19257
1 parent dc42e28 commit 8667022

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3840,7 +3840,7 @@ def check_assignment_to_multiple_lvalues(
38403840
if rvalue_needed > 0:
38413841
rvalues = (
38423842
rvalues[0:iterable_start]
3843-
+ [TempNode(iterable_type) for i in range(rvalue_needed)]
3843+
+ [TempNode(iterable_type, context=rval) for _ in range(rvalue_needed)]
38443844
+ rvalues[iterable_end + 1 :]
38453845
)
38463846

test-data/unit/check-lists.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,12 @@ def foo(x: object) -> None:
9494
[reveal_type(x) for x in [1, 2, 3]] # N: Revealed type is "builtins.int"
9595

9696
[builtins fixtures/isinstancelist.pyi]
97+
98+
[case testUnpackAssignmentWithStarExpr]
99+
a: A
100+
b: list[B]
101+
if int():
102+
(a,) = [*b] # E: Incompatible types in assignment (expression has type "B", variable has type "A")
103+
104+
class A: pass
105+
class B: pass

test-data/unit/check-tuples.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,15 @@ u, v, w = r, s = 1, 1 # E: Need more than 2 values to unpack (3 expected)
618618
d, e = f, g, h = 1, 1 # E: Need more than 2 values to unpack (3 expected)
619619
[builtins fixtures/tuple.pyi]
620620

621+
[case testUnpackAssignmentWithStarExpr]
622+
a: A
623+
b: list[B]
624+
if int():
625+
(a,) = (*b,) # E: Incompatible types in assignment (expression has type "B", variable has type "A")
626+
627+
class A: pass
628+
class B: pass
629+
621630

622631
-- Assignment to starred expressions
623632
-- ---------------------------------

0 commit comments

Comments
 (0)