Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/type_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
get_proper_type,
)

T = TypeVar("T")
T = TypeVar("T", covariant=True)


@trait
Expand Down
8 changes: 6 additions & 2 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3938,8 +3938,12 @@ def visit_type_alias_type(self, t: TypeAliasType, /) -> list[mypy.nodes.TypeAlia
assert t.alias is not None
if t.alias not in self.seen_alias_nodes:
self.seen_alias_nodes.add(t.alias)
return [t.alias] + t.alias.target.accept(self)
return []
res = [t.alias] + t.alias.target.accept(self)
else:
res = []
for arg in t.args:
res.extend(arg.accept(self))
return res


def is_named_instance(t: Type, fullnames: str | tuple[str, ...]) -> TypeGuard[Instance]:
Expand Down
9 changes: 9 additions & 0 deletions test-data/unit/check-recursive-types.test
Original file line number Diff line number Diff line change
Expand Up @@ -1014,3 +1014,12 @@ from bogus import Foo # type: ignore

A = Callable[[Foo, "B"], Foo] # E: Type alias target becomes "Callable[[Any, B], Any]" due to an unfollowed import
B = Callable[[Foo, A], Foo] # E: Type alias target becomes "Callable[[Any, A], Any]" due to an unfollowed import

[case testRecursiveAliasOnArgumentDetected]
from typing import TypeVar

T = TypeVar("T")
L = list[T]

A = L[A]
a: A = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "A")
Loading