[ty] detect cycles in binary comparison inference (#20446)
Some checks are pending
CI / cargo build (release) (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run

## Summary

Catch infinite recursion in binary-compare inference.

Fixes the stack overflow in `graphql-core` in mypy-primer.

## Test Plan

Added two tests that stack-overflowed before this PR.
This commit is contained in:
Carl Meyer 2025-09-17 00:45:25 -07:00 committed by GitHub
parent 9f0b942b9e
commit 99ec4d2c69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 101 additions and 28 deletions

View file

@ -392,3 +392,16 @@ class A:
# error: [unsupported-bool-conversion]
(A(),) == (A(),)
```
## Recursive NamedTuple
```py
from __future__ import annotations
from typing import NamedTuple
class Node(NamedTuple):
parent: Node | None
def _(n: Node):
reveal_type(n.parent is n) # revealed: bool
```

View file

@ -351,3 +351,12 @@ def f(x: A):
for item in x:
reveal_type(item) # revealed: list[A | str | None] | str | None
```
### Tuple comparison
```py
type X = tuple[X, int]
def _(x: X):
reveal_type(x is x) # revealed: bool
```