[ty] detect cycles in Type::is_disjoint_from (#19139)

This commit is contained in:
Carl Meyer 2025-07-04 06:31:44 -07:00 committed by GitHub
parent 7712c2fd15
commit 411cccb35e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 129 additions and 52 deletions

View file

@ -1862,6 +1862,21 @@ class Bar(Protocol):
static_assert(is_equivalent_to(Foo, Bar))
```
### Disjointness of recursive protocol and recursive final type
```py
from typing import Protocol
from ty_extensions import is_disjoint_from, static_assert
class Proto(Protocol):
x: "Proto"
class Nominal:
x: "Nominal"
static_assert(not is_disjoint_from(Proto, Nominal))
```
### Regression test: narrowing with self-referential protocols
This snippet caused us to panic on an early version of the implementation for protocols.