@@ -137,8 +137,7 @@ def func_error_alias1(
137137 reveal_type(b) # N: Revealed type is "builtins.dict[builtins.int, Any]"
138138 reveal_type(c) # N: Revealed type is "builtins.dict[builtins.int, builtins.float]"
139139
140- TERR2 = Dict[T4, T3] # TODO should be an error \
141- # Type parameter "T4" has a default type that refers to one or more type variables that are out of scope
140+ TERR2 = Dict[T4, T3] # E: Type parameter "T4" has a default type that refers to one or more type variables that are out of scope
142141
143142def func_error_alias2(
144143 a: TERR2,
@@ -518,8 +517,8 @@ def func_d3(
518517 reveal_type(b) # N: Revealed type is "__main__.ClassD3[builtins.int, builtins.list[builtins.int]]"
519518 reveal_type(c) # N: Revealed type is "__main__.ClassD3[builtins.int, builtins.float]"
520519
521- # k = ClassD3()
522- # reveal_type(k) # Revealed type is "__main__.ClassD3[builtins.str, builtins.list[builtins.str]]" # TODO
520+ k = ClassD3()
521+ reveal_type(k) # N: Revealed type is "__main__.ClassD3[builtins.str, builtins.list[builtins.str]]"
523522 l = ClassD3[int]()
524523 reveal_type(l) # N: Revealed type is "__main__.ClassD3[builtins.int, builtins.list[builtins.int]]"
525524 m = ClassD3[int, float]()
@@ -904,6 +903,19 @@ Alias: TypeAlias = "MyClass[T1, T2]"
904903class MyClass(Generic["T1", "T2"]): ...
905904[builtins fixtures/tuple.pyi]
906905
906+ [case testTypeVariableDefaultNotSticky]
907+ from typing import Generic, TypeVar
908+
909+ T1 = TypeVar("T1")
910+ T2 = TypeVar("T2", default=T1)
911+
912+ class MyClass(Generic[T1, T2]): ...
913+
914+ reveal_type(MyClass[int]) # N: Revealed type is "def () -> __main__.MyClass[builtins.int, builtins.int]"
915+ reveal_type(MyClass[str]) # N: Revealed type is "def () -> __main__.MyClass[builtins.str, builtins.str]"
916+ reveal_type(MyClass[bytes]) # N: Revealed type is "def () -> __main__.MyClass[builtins.bytes, builtins.bytes]"
917+ [builtins fixtures/tuple.pyi]
918+
907919[case testDefaultsApplicationInAliasNoCrashNested]
908920from typing import Generic, TypeVar
909921from typing_extensions import TypeAlias
@@ -928,19 +940,23 @@ T3 = TypeVar("T3", default=T2)
928940class A(Generic[T1, T2, T3]): ...
929941reveal_type(A) # N: Revealed type is "def [T1, T2 = T1`1, T3 = T2`2 = T1`1] () -> __main__.A[T1`1, T2`2 = T1`1, T3`3 = T2`2 = T1`1]"
930942a: A[int]
931- reveal_type(a) # N: Revealed type is "__main__.A[builtins.int, builtins.int, T1`1]"
943+ reveal_type(a) # N: Revealed type is "__main__.A[builtins.int, builtins.int, builtins.int]"
944+
945+ AA = tuple[T1, T2, T3]
946+ aa: AA[str]
947+ reveal_type(aa) # N: Revealed type is "tuple[builtins.str, builtins.str, builtins.str]"
932948
933- class B(Generic[T1, T3]): ... # E: Type variable T2 referenced in the default of T3 is unbound
949+ class B(Generic[T1, T3]): ... # E: Type parameter "T3" has a default type that refers to one or more type variables that are out of scope
934950reveal_type(B) # N: Revealed type is "def [T1, T3 = Any] () -> __main__.B[T1`1, T3`2 = Any]"
935951b: B[int]
936952reveal_type(b) # N: Revealed type is "__main__.B[builtins.int, Any]"
937953
938- class C(Generic[T2]): ... # E: Type variable T1 referenced in the default of T2 is unbound
954+ class C(Generic[T2]): ... # E: Type parameter "T2" has a default type that refers to one or more type variables that are out of scope
939955reveal_type(C) # N: Revealed type is "def [T2 = Any] () -> __main__.C[T2`1 = Any]"
940956c: C
941957reveal_type(c) # N: Revealed type is "__main__.C[Any]"
942958
943- class D(Generic[T2, T1]): ... # E: Type variable T1 referenced in the default of T2 is unbound \
959+ class D(Generic[T2, T1]): ... # E: Type parameter "T2" has a default type that refers to one or more type variables that are out of scope \
944960 # E: "T1" cannot appear after "T2" in type parameter list because it has no default type
945961reveal_type(D) # N: Revealed type is "def [T2 = Any, T1 = Any] () -> __main__.D[T2`1 = Any, T1`2 = Any]"
946962d: D
0 commit comments