mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-22 03:15:44 +00:00
[syntax-errors] Star annotations before Python 3.11 (#16545)
Summary -- This is closely related to (and stacked on) https://github.com/astral-sh/ruff/pull/16544 and detects star annotations in function definitions. I initially called the variant `StarExpressionInAnnotation` to mirror `StarExpressionInIndex`, but I realized it's not really a "star expression" in this position and renamed it. `StarAnnotation` seems in line with the PEP. Test Plan -- Two new inline tests. It looked like there was pretty good existing coverage of this syntax, so I just added simple examples to test the version cutoff.
This commit is contained in:
parent
4f2851982d
commit
6311412373
6 changed files with 199 additions and 2 deletions
|
@ -2882,9 +2882,23 @@ impl<'src> Parser<'src> {
|
|||
// def foo(*args: *int or str): ...
|
||||
// def foo(*args: *yield x): ...
|
||||
// # def foo(*args: **int): ...
|
||||
self.parse_conditional_expression_or_higher_impl(
|
||||
let parsed_expr = self.parse_conditional_expression_or_higher_impl(
|
||||
ExpressionContext::starred_bitwise_or(),
|
||||
)
|
||||
);
|
||||
|
||||
// test_ok param_with_star_annotation_py311
|
||||
// # parse_options: {"target-version": "3.11"}
|
||||
// def foo(*args: *Ts): ...
|
||||
|
||||
// test_err param_with_star_annotation_py310
|
||||
// # parse_options: {"target-version": "3.10"}
|
||||
// def foo(*args: *Ts): ...
|
||||
self.add_unsupported_syntax_error(
|
||||
UnsupportedSyntaxErrorKind::StarAnnotation,
|
||||
parsed_expr.range(),
|
||||
);
|
||||
|
||||
parsed_expr
|
||||
}
|
||||
AllowStarAnnotation::No => {
|
||||
// test_ok param_with_annotation
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue