Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4516,10 +4516,9 @@ def analyze_lvalue(
elif isinstance(lval, TupleExpr):
self.analyze_tuple_or_list_lvalue(lval, explicit_type)
elif isinstance(lval, StarExpr):
if nested:
self.analyze_lvalue(lval.expr, nested, explicit_type)
else:
if not nested:
self.fail("Starred assignment target must be in a list or tuple", lval)
self.analyze_lvalue(lval.expr, nested, explicit_type)
else:
self.fail("Invalid assignment target", lval)

Expand Down
6 changes: 6 additions & 0 deletions test-data/unit/check-statements.test
Original file line number Diff line number Diff line change
Expand Up @@ -2104,6 +2104,12 @@ if int():
-- ---------------


[case testInvalidBareStarAssignmentTargetNoCrash]
# https://github.com/python/mypy/issues/20796
# flags: --debug-serialize
*a = b # E: Starred assignment target must be in a list or tuple \
# E: Name "b" is not defined

[case testAssignListToStarExpr]
from typing import List
bs: List[A]
Expand Down
Loading