Skip to content

Commit 9c9b322

Browse files
committed
Fix visit_type_alias_type
1 parent c2eff4b commit 9c9b322

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

mypy/typeanal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,7 +2524,6 @@ def __init__(
25242524
self.api = api
25252525
self.tvar_expr_name = tvar_expr_name
25262526
self.context = context
2527-
self.seen_aliases: set[TypeAliasType] | None = None
25282527

25292528
def visit_unbound_type(self, t: UnboundType) -> Type:
25302529
sym = self.api.lookup_qualified(t.name, t, suppress_errors=True)
@@ -2541,4 +2540,5 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
25412540
return super().visit_unbound_type(t)
25422541

25432542
def visit_type_alias_type(self, t: TypeAliasType) -> Type:
2544-
raise NotImplementedError
2543+
# TypeAliasTypes are analyzed separately already, just return it
2544+
return t

test-data/unit/check-typevar-defaults.test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,3 +721,27 @@ def func_d1(
721721
reveal_type(b) # N: Revealed type is "builtins.dict[builtins.int, builtins.int]"
722722
reveal_type(c) # N: Revealed type is "builtins.dict[builtins.int, builtins.float]"
723723
[builtins fixtures/dict.pyi]
724+
725+
[case testTypeVarDefaultsTypeAliasRecursive2]
726+
from typing import Any, Dict, Generic, TypeVar
727+
728+
T1 = TypeVar("T1", default=str)
729+
T2 = TypeVar("T2", default=T1)
730+
Alias1 = Dict[T1, T2]
731+
T3 = TypeVar("T3")
732+
class A(Generic[T3]): ...
733+
734+
T4 = TypeVar("T4", default=A[Alias1])
735+
class B(Generic[T4]): ...
736+
737+
def func_d3(
738+
a: B,
739+
b: B[A[Alias1[int]]],
740+
c: B[A[Alias1[int, float]]],
741+
d: B[int],
742+
) -> None:
743+
reveal_type(a) # N: Revealed type is "__main__.B[__main__.A[builtins.dict[builtins.str, builtins.str]]]"
744+
reveal_type(b) # N: Revealed type is "__main__.B[__main__.A[builtins.dict[builtins.int, builtins.int]]]"
745+
reveal_type(c) # N: Revealed type is "__main__.B[__main__.A[builtins.dict[builtins.int, builtins.float]]]"
746+
reveal_type(d) # N: Revealed type is "__main__.B[builtins.int]"
747+
[builtins fixtures/dict.pyi]

0 commit comments

Comments
 (0)