[ty] add support for cyclic legacy generic protocols (#20125)

## Summary

Just add the necessary Salsa cycle handling.

## Test Plan

Added mdtest.
This commit is contained in:
Carl Meyer 2025-08-28 09:58:01 -07:00 committed by GitHub
parent f4362b95d7
commit 9363eeca26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 1 deletions

View file

@ -2339,6 +2339,28 @@ class Bar(Protocol[S]):
z: S | Bar[S]
```
### Recursive legacy generic protocol
```py
from typing import Generic, TypeVar, Protocol
T = TypeVar("T")
class P(Protocol[T]):
attr: "P[T] | T"
class A(Generic[T]):
attr: T
class B(A[P[int]]):
pass
def f(b: B):
reveal_type(b) # revealed: B
reveal_type(b.attr) # revealed: P[int]
reveal_type(b.attr.attr) # revealed: P[int] | int
```
### Recursive generic protocols with property members
An early version of <https://github.com/astral-sh/ruff/pull/19936> caused stack overflows on this