[syntax-errors] type alias statements before Python 3.12 (#16478)

Summary
--
Another simple one, just detect standalone `type` statements. I limited
the diagnostic to `type` itself like [pyright]. That probably makes the
most sense for more complicated examples.

Test Plan
--
Inline tests.

[pyright]:
https://pyright-play.net/?pythonVersion=3.8&strict=true&code=C4TwDgpgBAHlC8UCWA7YQ
This commit is contained in:
Brent Westbrook 2025-03-04 12:20:10 -05:00 committed by GitHub
parent 087d92cbf4
commit 32c66ec4b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 98 additions and 0 deletions

View file

@ -0,0 +1,42 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/type_stmt_py311.py
---
## AST
```
Module(
ModModule {
range: 0..57,
body: [
TypeAlias(
StmtTypeAlias {
range: 44..56,
name: Name(
ExprName {
range: 49..50,
id: Name("x"),
ctx: Store,
},
),
type_params: None,
value: Name(
ExprName {
range: 53..56,
id: Name("int"),
ctx: Load,
},
),
},
),
],
},
)
```
## Unsupported Syntax Errors
|
1 | # parse_options: {"target-version": "3.11"}
2 | type x = int
| ^^^^ Syntax Error: Cannot use `type` alias statement on Python 3.11 (syntax was added in Python 3.12)
|

View file

@ -0,0 +1,35 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/ok/type_stmt_py312.py
---
## AST
```
Module(
ModModule {
range: 0..57,
body: [
TypeAlias(
StmtTypeAlias {
range: 44..56,
name: Name(
ExprName {
range: 49..50,
id: Name("x"),
ctx: Store,
},
),
type_params: None,
value: Name(
ExprName {
range: 53..56,
id: Name("int"),
ctx: Load,
},
),
},
),
],
},
)
```