mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-23 02:23:18 +00:00
[syntax-errors] Tuple unpacking in return
and yield
before Python 3.8 (#16485)
Summary -- Checks for tuple unpacking in `return` and `yield` statements before Python 3.8, as described [here]. Test Plan -- Inline tests. [here]: https://github.com/python/cpython/issues/76298
This commit is contained in:
parent
0a627ef216
commit
6c14225c66
15 changed files with 1217 additions and 8 deletions
|
@ -11,6 +11,7 @@ use ruff_python_ast::{
|
|||
};
|
||||
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
|
||||
|
||||
use crate::error::StarTupleKind;
|
||||
use crate::parser::progress::ParserProgress;
|
||||
use crate::parser::{helpers, FunctionKind, Parser};
|
||||
use crate::string::{parse_fstring_literal_element, parse_string_literal, StringType};
|
||||
|
@ -2089,10 +2090,27 @@ impl<'src> Parser<'src> {
|
|||
}
|
||||
|
||||
let value = self.at_expr().then(|| {
|
||||
Box::new(
|
||||
self.parse_expression_list(ExpressionContext::starred_bitwise_or())
|
||||
.expr,
|
||||
)
|
||||
let parsed_expr = self.parse_expression_list(ExpressionContext::starred_bitwise_or());
|
||||
|
||||
// test_ok iter_unpack_yield_py37
|
||||
// # parse_options: {"target-version": "3.7"}
|
||||
// rest = (4, 5, 6)
|
||||
// def g(): yield (1, 2, 3, *rest)
|
||||
|
||||
// test_ok iter_unpack_yield_py38
|
||||
// # parse_options: {"target-version": "3.8"}
|
||||
// rest = (4, 5, 6)
|
||||
// def g(): yield 1, 2, 3, *rest
|
||||
// def h(): yield 1, (yield 2, *rest), 3
|
||||
|
||||
// test_err iter_unpack_yield_py37
|
||||
// # parse_options: {"target-version": "3.7"}
|
||||
// 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);
|
||||
|
||||
Box::new(parsed_expr.expr)
|
||||
});
|
||||
|
||||
Expr::Yield(ast::ExprYield {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue