[ty] add cycle detection for find_legacy_typevars (#20124)

## Summary

Add cycle detection to the `find_legacy_typevars` type method.

## Test Plan

Added mdtest that stack overflowed without this.
This commit is contained in:
Carl Meyer 2025-08-28 09:55:08 -07:00 committed by GitHub
parent f703536977
commit f4362b95d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 188 additions and 102 deletions

View file

@ -217,6 +217,26 @@ def f(x: IntOr, y: OrInt):
reveal_type(y) # revealed: Never
```
### With legacy generic
```py
from typing import Generic, TypeVar
T = TypeVar("T")
type Alias = list["Alias"] | int
class A(Generic[T]):
attr: T
class B(A[Alias]):
pass
def f(b: B):
reveal_type(b) # revealed: B
reveal_type(b.attr) # revealed: list[Alias] | int
```
### Mutually recursive
```py