mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-22 03:15:44 +00:00
[syntax-errors] Type parameter lists before Python 3.12 (#16479)
Summary -- Another simple one, just detect type parameter lists in functions and classes. Like pyright, we don't emit a second diagnostic for `type` alias statements, which were also introduced in 3.12. Test Plan -- Inline tests.
This commit is contained in:
parent
d94a78a134
commit
81bcdcebd3
10 changed files with 557 additions and 0 deletions
|
@ -1786,6 +1786,21 @@ impl<'src> Parser<'src> {
|
|||
// x = 10
|
||||
let type_params = self.try_parse_type_params();
|
||||
|
||||
// test_ok function_type_params_py312
|
||||
// # parse_options: {"target-version": "3.12"}
|
||||
// def foo[T](): ...
|
||||
|
||||
// test_err function_type_params_py311
|
||||
// # parse_options: {"target-version": "3.11"}
|
||||
// def foo[T](): ...
|
||||
// def foo[](): ...
|
||||
if let Some(ast::TypeParams { range, .. }) = &type_params {
|
||||
self.add_unsupported_syntax_error(
|
||||
UnsupportedSyntaxErrorKind::TypeParameterList,
|
||||
*range,
|
||||
);
|
||||
}
|
||||
|
||||
// test_ok function_def_parameter_range
|
||||
// def foo(
|
||||
// first: int,
|
||||
|
@ -1900,6 +1915,21 @@ impl<'src> Parser<'src> {
|
|||
// x = 10
|
||||
let type_params = self.try_parse_type_params();
|
||||
|
||||
// test_ok class_type_params_py312
|
||||
// # parse_options: {"target-version": "3.12"}
|
||||
// class Foo[S: (str, bytes), T: float, *Ts, **P]: ...
|
||||
|
||||
// test_err class_type_params_py311
|
||||
// # parse_options: {"target-version": "3.11"}
|
||||
// class Foo[S: (str, bytes), T: float, *Ts, **P]: ...
|
||||
// class Foo[]: ...
|
||||
if let Some(ast::TypeParams { range, .. }) = &type_params {
|
||||
self.add_unsupported_syntax_error(
|
||||
UnsupportedSyntaxErrorKind::TypeParameterList,
|
||||
*range,
|
||||
);
|
||||
}
|
||||
|
||||
// test_ok class_def_arguments
|
||||
// class Foo: ...
|
||||
// class Foo(): ...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue