@@ -1494,3 +1494,34 @@ reveal_type(a) # N: Revealed type is "builtins.list[builtins.int]"
14941494# flags: --enable-incomplete-feature=NewGenericSyntax
14951495def f[T](x: foobar, y: T) -> T: ... # E: Name "foobar" is not defined
14961496reveal_type(f) # N: Revealed type is "def [T] (x: Any, y: T`-1) -> T`-1"
1497+
1498+ [case testPEP695WrongNumberOfConstrainedTypes]
1499+ # flags: --enable-incomplete-feature=NewGenericSyntax
1500+ type A[T: ()] = list[T] # E: Type variable must have at least two constrained types
1501+ a: A[int]
1502+ reveal_type(a) # N: Revealed type is "builtins.list[builtins.int]"
1503+
1504+ type B[T: (int,)] = list[T] # E: Type variable must have at least two constrained types
1505+ b: B[str]
1506+ reveal_type(b) # N: Revealed type is "builtins.list[builtins.str]"
1507+
1508+ [case testPEP695UsingTypeVariableInOwnBoundOrConstraint]
1509+ # flags: --enable-incomplete-feature=NewGenericSyntax
1510+ type A[T: list[T]] = str # E: Name "T" is not defined
1511+ type B[S: (list[S], str)] = str # E: Name "S" is not defined
1512+ type C[T, S: list[T]] = str # E: Name "T" is not defined
1513+
1514+ def f[T: T](x: T) -> T: ... # E: Name "T" is not defined
1515+ class D[T: T]: # E: Name "T" is not defined
1516+ pass
1517+
1518+ [case testPEP695InvalidType]
1519+ # flags: --enable-incomplete-feature=NewGenericSyntax
1520+ def f[T: 1](x: T) -> T: ... # E: Invalid type: try using Literal[1] instead?
1521+ class C[T: (int, (1 + 2))]: pass # E: Invalid type comment or annotation
1522+ type A = list[1] # E: Invalid type: try using Literal[1] instead?
1523+ type B = (1 + 2) # E: Invalid type alias: expression is not a valid type
1524+ a: A
1525+ reveal_type(a) # N: Revealed type is "builtins.list[Any]"
1526+ b: B
1527+ reveal_type(b) # N: Revealed type is "Any"
0 commit comments