[syntax-errors] except* before Python 3.11 (#16446)

Summary
--

One of the simpler ones, just detect the use of `except*` before 3.11.

Test Plan
--

New inline tests.
This commit is contained in:
Brent Westbrook 2025-03-02 13:20:18 -05:00 committed by GitHub
parent 0d615b8765
commit e924ecbdac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 180 additions and 23 deletions

View file

@ -0,0 +1,72 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/except_star_py310.py
---
## AST
```
Module(
ModModule {
range: 0..77,
body: [
Try(
StmtTry {
range: 44..76,
body: [
Expr(
StmtExpr {
range: 49..52,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 49..52,
},
),
},
),
],
handlers: [
ExceptHandler(
ExceptHandlerExceptHandler {
range: 53..76,
type_: Some(
Name(
ExprName {
range: 61..71,
id: Name("ValueError"),
ctx: Load,
},
),
),
name: None,
body: [
Expr(
StmtExpr {
range: 73..76,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 73..76,
},
),
},
),
],
},
),
],
orelse: [],
finalbody: [],
is_star: true,
},
),
],
},
)
```
## Unsupported Syntax Errors
|
1 | # parse_options: {"target-version": "3.10"}
2 | / try: ...
3 | | except* ValueError: ...
| |_______________________^ Syntax Error: Cannot use `except*` on Python 3.10 (syntax was added in Python 3.11)
|

View file

@ -0,0 +1,64 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/ok/except_star_py311.py
---
## AST
```
Module(
ModModule {
range: 0..77,
body: [
Try(
StmtTry {
range: 44..76,
body: [
Expr(
StmtExpr {
range: 49..52,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 49..52,
},
),
},
),
],
handlers: [
ExceptHandler(
ExceptHandlerExceptHandler {
range: 53..76,
type_: Some(
Name(
ExprName {
range: 61..71,
id: Name("ValueError"),
ctx: Load,
},
),
),
name: None,
body: [
Expr(
StmtExpr {
range: 73..76,
value: EllipsisLiteral(
ExprEllipsisLiteral {
range: 73..76,
},
),
},
),
],
},
),
],
orelse: [],
finalbody: [],
is_star: true,
},
),
],
},
)
```