mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-22 11:25:26 +00:00
[syntax-errors] Type parameter defaults before Python 3.13 (#16447)
Summary -- Detects the presence of a [PEP 696] type parameter default before Python 3.13. Test Plan -- New inline parser tests for type aliases, generic functions and generic classes. [PEP 696]: https://peps.python.org/pep-0696/#grammar-changes
This commit is contained in:
parent
c8a06a9be8
commit
e7b93f93ef
6 changed files with 514 additions and 4 deletions
|
@ -3243,6 +3243,7 @@ impl<'src> Parser<'src> {
|
|||
None
|
||||
};
|
||||
|
||||
let equal_token_start = self.node_start();
|
||||
let default = if self.eat(TokenKind::Equal) {
|
||||
if self.at_expr() {
|
||||
// test_err type_param_type_var_invalid_default_expr
|
||||
|
@ -3268,6 +3269,26 @@ impl<'src> Parser<'src> {
|
|||
None
|
||||
};
|
||||
|
||||
// test_ok type_param_default_py313
|
||||
// # parse_options: {"target-version": "3.13"}
|
||||
// type X[T = int] = int
|
||||
// def f[T = int](): ...
|
||||
// class C[T = int](): ...
|
||||
|
||||
// test_err type_param_default_py312
|
||||
// # parse_options: {"target-version": "3.12"}
|
||||
// type X[T = int] = int
|
||||
// def f[T = int](): ...
|
||||
// class C[T = int](): ...
|
||||
// class D[S, T = int, U = uint](): ...
|
||||
|
||||
if default.is_some() {
|
||||
self.add_unsupported_syntax_error(
|
||||
UnsupportedSyntaxErrorKind::TypeParamDefault,
|
||||
self.node_range(equal_token_start),
|
||||
);
|
||||
}
|
||||
|
||||
ast::TypeParam::TypeVar(ast::TypeParamTypeVar {
|
||||
range: self.node_range(start),
|
||||
name,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue