mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:24:57 +00:00
[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:
parent
f703536977
commit
f4362b95d7
11 changed files with 188 additions and 102 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue