Skip to content

Commit 7669841

Browse files
authored
Fix crash on recursive alias in indirection.py (#19845)
Fixes #19836 Fix is trivial, I am surprised none of the existing tests caught this in the original PR. After this is merged, I am going to add the test to `master`.
1 parent 03fbaa9 commit 7669841

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

mypy/indirection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ def find_modules(self, typs: Iterable[types.Type]) -> set[str]:
3939
def _visit(self, typ: types.Type) -> None:
4040
if isinstance(typ, types.TypeAliasType):
4141
# Avoid infinite recursion for recursive type aliases.
42-
if typ not in self.seen_aliases:
43-
self.seen_aliases.add(typ)
42+
if typ in self.seen_aliases:
43+
return
44+
self.seen_aliases.add(typ)
4445
typ.accept(self)
4546

4647
def _visit_type_tuple(self, typs: tuple[types.Type, ...]) -> None:

test-data/unit/check-incremental.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,6 +2577,13 @@ C(1)[0]
25772577
[builtins fixtures/list.pyi]
25782578
[out]
25792579

2580+
[case testSerializeRecursiveAlias]
2581+
from typing import Callable, Union
2582+
2583+
Node = Union[str, int, Callable[[], "Node"]]
2584+
n: Node
2585+
[out]
2586+
25802587
[case testSerializeRecursiveAliases1]
25812588

25822589
from typing import Type, Callable, Union

0 commit comments

Comments
 (0)