[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:
@@ -2130,7 +2130,10 @@ impl<'src> Parser<'src> {
|
||||
// rest = (4, 5, 6)
|
||||
// def g(): yield 1, 2, 3, *rest
|
||||
// def h(): yield 1, (yield 2, *rest), 3
|
||||
self.check_tuple_unpacking(&parsed_expr, StarTupleKind::Yield);
|
||||
self.check_tuple_unpacking(
|
||||
&parsed_expr,
|
||||
UnsupportedSyntaxErrorKind::StarTuple(StarTupleKind::Yield),
|
||||
);
|
||||
|
||||
Box::new(parsed_expr.expr)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user