2Tests generic type aliases used in class declarations for
3variance incompatibility.
6from typing import Generic, TypeVar, TypeAlias
9T_co = TypeVar("T_co", covariant=True)
10T_contra = TypeVar("T_contra", contravariant=True)
13class ClassA(Generic[T]):
17A_Alias_1: TypeAlias = ClassA[T_co]
18A_Alias_2: TypeAlias = A_Alias_1[T_co]
20# Specialized type aliases used within a class declaration should
21# result in the same variance incompatibility errors as their
22# non-aliased counterparts.
24class ClassA_1(ClassA[T_co]): # E: incompatible variance
Expected a ty diagnostic for this line
28class ClassA_2(A_Alias_1[T_co]): # E: incompatible variance
Expected a ty diagnostic for this line
32class ClassA_3(A_Alias_2[T_co]): # E: incompatible variance
Expected a ty diagnostic for this line
37class ClassB(Generic[T, T_co]):
41B_Alias_1 = ClassB[T_co, T_contra]
44class ClassB_1(B_Alias_1[T_contra, T_co]): # E: incompatible variance
Expected a ty diagnostic for this line