[syntax-errors] Tuple unpacking in for statement iterator clause before Python 3.9 (#16558)

Summary
--

This PR reuses a slightly modified version of the
`check_tuple_unpacking` method added for detecting unpacking in `return`
and `yield` statements to detect the same issue in the iterator clause
of `for` loops.

I ran into the same issue with a bare `for x in *rest: ...` example
(invalid even on Python 3.13) and added it as a comment on
https://github.com/astral-sh/ruff/issues/16520.

I considered just making this an additional `StarTupleKind` variant as
well, but this change was in a different version of Python, so I kept it
separate.

Test Plan
--

New inline tests.
This commit is contained in:
Brent Westbrook 2025-03-13 15:55:17 -04:00 committed by GitHub
parent 27e9d1fe3e
commit 2382fe1f25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 673 additions and 6 deletions

View file

@ -0,0 +1,4 @@
# parse_options: {"target-version": "3.8"}
for x in *a, b: ...
for x in a, *b: ...
for x in *a, *b: ...

View file

@ -0,0 +1,4 @@
# parse_options: {"target-version": "3.8"}
for x in (*a, b): ...
for x in ( a, *b): ...
for x in (*a, *b): ...

View file

@ -0,0 +1,4 @@
# parse_options: {"target-version": "3.9"}
for x in *a, b: ...
for x in a, *b: ...
for x in *a, *b: ...