@@ -449,6 +449,34 @@ pub enum UnsupportedSyntaxErrorKind {
449
449
Match ,
450
450
Walrus ,
451
451
ExceptStar ,
452
+ /// Represents the use of a [type parameter list] before Python 3.12.
453
+ ///
454
+ /// ## Examples
455
+ ///
456
+ /// Before Python 3.12, generic parameters had to be declared separately using a class like
457
+ /// [`typing.TypeVar`], which could then be used in a function or class definition:
458
+ ///
459
+ /// ```python
460
+ /// from typing import Generic, TypeVar
461
+ ///
462
+ /// T = TypeVar("T")
463
+ ///
464
+ /// def f(t: T): ...
465
+ /// class C(Generic[T]): ...
466
+ /// ```
467
+ ///
468
+ /// [PEP 695], included in Python 3.12, introduced the new type parameter syntax, which allows
469
+ /// these to be written more compactly and without a separate type variable:
470
+ ///
471
+ /// ```python
472
+ /// def f[T](t: T): ...
473
+ /// class C[T]: ...
474
+ /// ```
475
+ ///
476
+ /// [type parameter list]: https://docs.python.org/3/reference/compound_stmts.html#type-parameter-lists
477
+ /// [PEP 695]: https://peps.python.org/pep-0695/
478
+ /// [`typing.TypeVar`]: https://docs.python.org/3/library/typing.html#typevar
479
+ TypeParameterList ,
452
480
TypeAliasStatement ,
453
481
TypeParamDefault ,
454
482
}
@@ -459,6 +487,7 @@ impl Display for UnsupportedSyntaxError {
459
487
UnsupportedSyntaxErrorKind :: Match => "Cannot use `match` statement" ,
460
488
UnsupportedSyntaxErrorKind :: Walrus => "Cannot use named assignment expression (`:=`)" ,
461
489
UnsupportedSyntaxErrorKind :: ExceptStar => "Cannot use `except*`" ,
490
+ UnsupportedSyntaxErrorKind :: TypeParameterList => "Cannot use type parameter lists" ,
462
491
UnsupportedSyntaxErrorKind :: TypeAliasStatement => "Cannot use `type` alias statement" ,
463
492
UnsupportedSyntaxErrorKind :: TypeParamDefault => {
464
493
"Cannot set default type for a type parameter"
@@ -480,6 +509,7 @@ impl UnsupportedSyntaxErrorKind {
480
509
UnsupportedSyntaxErrorKind :: Match => PythonVersion :: PY310 ,
481
510
UnsupportedSyntaxErrorKind :: Walrus => PythonVersion :: PY38 ,
482
511
UnsupportedSyntaxErrorKind :: ExceptStar => PythonVersion :: PY311 ,
512
+ UnsupportedSyntaxErrorKind :: TypeParameterList => PythonVersion :: PY312 ,
483
513
UnsupportedSyntaxErrorKind :: TypeAliasStatement => PythonVersion :: PY312 ,
484
514
UnsupportedSyntaxErrorKind :: TypeParamDefault => PythonVersion :: PY313 ,
485
515
}
0 commit comments