← Back to index

generics_syntax_compatibility.py

True Positive
False Positive
False Negative
Optional (detected)
Warning or Info
TP: 0
FP: 0
FN: 2
Optional: 0 / 0
1"""
2Tests the compatibility rules between type parameter syntax (introduced in PEP 695)
3and traditional TypeVars.
4"""
5
6# Specification: https://peps.python.org/pep-0695/#compatibility-with-traditional-typevars
7
8from typing import TypeVar
9
11K = TypeVar("K")
14class ClassA[V](dict[K, V]): # E: traditional TypeVar not allowed here
Expected a ty diagnostic for this line
15 ...
18class ClassB[K, V](dict[K, V]): # OK
19 ...
22class ClassC[V]:
23 def method1(self, a: V, b: K) -> V | K: # OK
24 raise NotImplementedError
26 def method2[M](self, a: M, b: K) -> M | K: # E
Expected a ty diagnostic for this line
27 raise NotImplementedError