Skip to content

Commit 0a2424e

Browse files
authored
Fix crash on invalid star lvalue (#22222)
Fixes #20796 I think the correct fix is to not create any placeholders in the first place, since this is essentially a syntax error.
1 parent 58a63c9 commit 0a2424e

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎mypy/semanal.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8496,16 +8496,16 @@ def names_modified_by_assignment(s: AssignmentStmt) -> list[NameExpr]:
84968496
return result
84978497

84988498

8499-
def names_modified_in_lvalue(lvalue: Lvalue) -> list[NameExpr]:
8499+
def names_modified_in_lvalue(lvalue: Lvalue, include_star: bool = False) -> list[NameExpr]:
85008500
"""Return all NameExpr assignment targets in an Lvalue."""
85018501
if isinstance(lvalue, NameExpr):
85028502
return [lvalue]
8503-
elif isinstance(lvalue, StarExpr):
8503+
elif isinstance(lvalue, StarExpr) and include_star:
85048504
return names_modified_in_lvalue(lvalue.expr)
85058505
elif isinstance(lvalue, (ListExpr, TupleExpr)):
85068506
result: list[NameExpr] = []
85078507
for item in lvalue.items:
8508-
result += names_modified_in_lvalue(item)
8508+
result += names_modified_in_lvalue(item, include_star=True)
85098509
return result
85108510
return []
85118511

‎test-data/unit/check-incremental.test‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8293,3 +8293,15 @@ Jérôme = False
82938293
[stale]
82948294
[out]
82958295
[out2]
8296+
8297+
[case testInvalidUnpackTargetFromUndefinedNoCrash]
8298+
*a = b
8299+
a
8300+
[out]
8301+
main:1: error: Starred assignment target must be in a list or tuple
8302+
main:1: error: Name "b" is not defined
8303+
main:2: error: Name "a" is not defined
8304+
[out2]
8305+
main:1: error: Starred assignment target must be in a list or tuple
8306+
main:1: error: Name "b" is not defined
8307+
main:2: error: Name "a" is not defined

0 commit comments

Comments
 (0)