Skip to content

Conversation

mtshiba
Copy link
Contributor

@mtshiba mtshiba commented Sep 23, 2025

Summary

Implements bidirectional type inference using function return type annotations.

This PR was originally proposed to solve astral-sh/ty#1167, but this does not fully resolve it on its own.
Additionally, I believe we need to allow dataclasses to generate their own __new__ methods, use constructor return types ​​for inference, and a mechanism to discard type narrowing like & ~AlwaysFalsy if necessary (at a more general level than this PR).

Test Plan

mdtest/bidirectional.md is added.

@mtshiba mtshiba changed the title [ty] propagate the annotated return type of functions to the inference of expressions in return statements [ty] bidirectional type inference using function return type annotations Sep 23, 2025
Copy link
Contributor

github-actions bot commented Sep 23, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

Copy link
Contributor

github-actions bot commented Sep 23, 2025

mypy_primer results

Changes were detected when running on open source projects
pip (https://github.com/pypa/pip)
- src/pip/_vendor/resolvelib/resolvers/resolution.py:597:16: error[invalid-return-type] Return type does not match returned value: expected `Result[RT@Resolver, CT@Resolver, KT@Resolver]`, found `Result[Unknown, Unknown | None, Unknown]`
+ src/pip/_vendor/resolvelib/resolvers/resolution.py:597:16: error[invalid-return-type] Return type does not match returned value: expected `Result[RT@Resolver, CT@Resolver, KT@Resolver]`, found `Result[RT@Resolver | Unknown, CT@Resolver | Unknown | None, KT@Resolver | None | Unknown]`

spack (https://github.com/spack/spack)
- lib/spack/spack/installer.py:2185:27: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `set[str] | None`
+ lib/spack/spack/installer.py:2185:27: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[str]`, found `set[str] | None`

werkzeug (https://github.com/pallets/werkzeug)
- src/werkzeug/local.py:511:24: error[invalid-return-type] Return type does not match returned value: expected `T@LocalProxy`, found `~None | Unknown`
+ src/werkzeug/local.py:511:24: error[invalid-return-type] Return type does not match returned value: expected `T@LocalProxy`, found `T@LocalProxy | ~None | Unknown`
+ src/werkzeug/routing/exceptions.py:107:20: error[no-matching-overload] No overload of function `max` matches arguments
- Found 364 diagnostics
+ Found 365 diagnostics

aiortc (https://github.com/aiortc/aiortc)
- src/aiortc/codecs/g711.py:65:20: error[invalid-return-type] Return type does not match returned value: expected `tuple[list[bytes], int]`, found `tuple[list[Unknown], None]`
+ src/aiortc/codecs/g711.py:65:20: error[invalid-return-type] Return type does not match returned value: expected `tuple[list[bytes], int]`, found `tuple[list[bytes], None]`
- src/aiortc/codecs/g722.py:73:20: error[invalid-return-type] Return type does not match returned value: expected `tuple[list[bytes], int]`, found `tuple[list[Unknown], None]`
+ src/aiortc/codecs/g722.py:73:20: error[invalid-return-type] Return type does not match returned value: expected `tuple[list[bytes], int]`, found `tuple[list[bytes], None]`
- src/aiortc/codecs/opus.py:73:20: error[invalid-return-type] Return type does not match returned value: expected `tuple[list[bytes], int]`, found `tuple[list[Unknown], None]`
+ src/aiortc/codecs/opus.py:73:20: error[invalid-return-type] Return type does not match returned value: expected `tuple[list[bytes], int]`, found `tuple[list[bytes], None]`

pytest (https://github.com/pytest-dev/pytest)
- testing/python/raises_group.py:33:12: error[invalid-return-type] Return type does not match returned value: expected `RaisesExc[Failed]`, found `RaisesExc[BaseException]`
- Found 480 diagnostics
+ Found 479 diagnostics

paasta (https://github.com/yelp/paasta)
- paasta_tools/cli/cmds/mesh_status.py:117:16: error[invalid-return-type] Return type does not match returned value: expected `tuple[int, list[str]]`, found `tuple[Unknown | None, list[Unknown | str]]`
+ paasta_tools/cli/cmds/mesh_status.py:117:16: error[invalid-return-type] Return type does not match returned value: expected `tuple[int, list[str]]`, found `tuple[Unknown | None, list[str]]`

sockeye (https://github.com/awslabs/sockeye)
- sockeye/data_io.py:1149:62: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Unknown]`, found `list[tuple[int | float | None, int | float | None]] | None`
+ sockeye/data_io.py:1149:62: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[tuple[int | float | None, int | float | None]]`, found `list[tuple[int | float | None, int | float | None]] | None`
- sockeye/model.py:816:56: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Unknown]`, found `list[int] | None`
+ sockeye/model.py:816:56: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[int]`, found `list[int] | None`
- test/unit/test_inference.py:177:114: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Unknown]`, found `list[Any] | None`
+ test/unit/test_inference.py:177:114: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Any]`, found `list[Any] | None`

pydantic (https://github.com/pydantic/pydantic)
- pydantic/_internal/_validators.py:162:16: error[invalid-return-type] Return type does not match returned value: expected `Pattern[bytes]`, found `Pattern[str]`
+ pydantic/_internal/_validators.py:162:16: error[invalid-return-type] Return type does not match returned value: expected `Pattern[bytes]`, found `Pattern[bytes | str]`

schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/specs/openapi/stateful/__init__.py:194:36: error[invalid-return-type] Return type does not match returned value: expected `Case`, found `type[APIStateMachine]`
+ src/schemathesis/specs/openapi/stateful/__init__.py:195:32: error[invalid-return-type] Return type does not match returned value: expected `Case`, found `type[APIStateMachine]`
- Found 271 diagnostics
+ Found 273 diagnostics

Expression (https://github.com/cognitedata/Expression)
- expression/extra/option/pipeline.py:91:19: error[invalid-argument-type] Argument to function `reduce` is incorrect: Expected `(def Some[_T1](value: _T1@Some) -> Option[_T1@Some], (Any, /) -> Option[Any], /) -> def Some[_T1](value: _T1@Some) -> Option[_T1@Some]`, found `def reducer(acc: (Any, /) -> Option[Any], fn: (Any, /) -> Option[Any]) -> (Any, /) -> Option[Any]`
- expression/extra/result/pipeline.py:96:19: error[invalid-argument-type] Argument to function `reduce` is incorrect: Expected `(def Ok[_TSource](value: _TSource@Ok) -> Result[_TSource@Ok, Any], (Any, /) -> Result[Any, Any], /) -> def Ok[_TSource](value: _TSource@Ok) -> Result[_TSource@Ok, Any]`, found `def reducer(acc: (Any, /) -> Result[Any, Any], fn: (Any, /) -> Result[Any, Any]) -> (Any, /) -> Result[Any, Any]`
- Found 211 diagnostics
+ Found 209 diagnostics

mypy (https://github.com/python/mypy)
+ mypy/join.py:253:21: error[invalid-argument-type] Argument to bound method `accept` is incorrect: Expected `TypeVisitor[Type]`, found `TypeJoinVisitor`
- Found 1854 diagnostics
+ Found 1855 diagnostics

sphinx (https://github.com/sphinx-doc/sphinx)
- sphinx/environment/adapters/toctree.py:559:16: error[invalid-return-type] Return type does not match returned value: expected `list[Element]`, found `list[Unknown | Node]`
+ sphinx/environment/adapters/toctree.py:559:16: error[invalid-return-type] Return type does not match returned value: expected `list[Element]`, found `list[Node]`

trio (https://github.com/python-trio/trio)
- src/trio/_tests/test_testing_raisesgroup.py:28:12: error[invalid-return-type] Return type does not match returned value: expected `RaisesExc[AssertionError]`, found `RaisesExc[BaseException]`
+ src/trio/testing/_trio_test.py:44:16: error[invalid-return-type] Return type does not match returned value: expected `RetT@trio_test`, found `(...) -> RetT@trio_test`

mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
- pymongo/synchronous/pool.py:413:20: error[invalid-return-type] Return type does not match returned value: expected `dict[str, Any]`, found `Mapping[str, Any]`
+ pymongo/synchronous/pool.py:413:20: error[invalid-return-type] Return type does not match returned value: expected `dict[str, Any]`, found `dict[str, Any] | Mapping[str, Any]`

openlibrary (https://github.com/internetarchive/openlibrary)
- openlibrary/plugins/upstream/models.py:586:28: error[invalid-return-type] Return type does not match returned value: expected `list[Image]`, found `list[Unknown | (Edition & ~AlwaysTruthy & ~AlwaysFalsy) | (Unknown & ~AlwaysFalsy)]`
+ openlibrary/plugins/upstream/models.py:586:28: error[invalid-return-type] Return type does not match returned value: expected `list[Image]`, found `list[Image | (Edition & ~AlwaysTruthy & ~AlwaysFalsy) | (Unknown & ~AlwaysFalsy)]`
- openlibrary/plugins/worksearch/code.py:453:34: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Unknown]`, found `list[str] | None`
+ openlibrary/plugins/worksearch/code.py:453:34: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[str]`, found `list[str] | None`
- openlibrary/plugins/worksearch/code.py:453:61: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Unknown]`, found `list[str] | None`
+ openlibrary/plugins/worksearch/code.py:453:61: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[str]`, found `list[str] | None`

strawberry (https://github.com/strawberry-graphql/strawberry)
+ strawberry/federation/object_type.py:90:9: error[invalid-argument-type] Argument to function `type` is incorrect: Expected `T@_impl_type`, found `T@_impl_type | None`
- Found 378 diagnostics
+ Found 379 diagnostics

meson (https://github.com/mesonbuild/meson)
- mesonbuild/scripts/symbolextractor.py:221:16: error[invalid-return-type] Return type does not match returned value: expected `tuple[list[str], str]`, found `tuple[list[Unknown | (str & ~AlwaysFalsy)], None]`
+ mesonbuild/scripts/symbolextractor.py:221:16: error[invalid-return-type] Return type does not match returned value: expected `tuple[list[str], str]`, found `tuple[list[str], None]`
- mesonbuild/utils/universal.py:1689:12: error[invalid-return-type] Return type does not match returned value: expected `list[str]`, found `list[Any | Sequence[Any]]`
+ mesonbuild/utils/universal.py:1689:12: error[invalid-return-type] Return type does not match returned value: expected `list[str]`, found `list[str | Any | Sequence[Any]]`

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/wrapper/_implementations.py:945:16: error[invalid-return-type] Return type does not match returned value: expected `DataClass_ | type[@Todo] | ListConfig | DictConfig`, found `@Todo | (((...) -> Any) & Top[dict[Unknown, Unknown]]) | (DataClass_ & Top[dict[Unknown, Unknown]]) | dict[Any, Any] | (ListConfig & Top[dict[Unknown, Unknown]]) | (DictConfig & Top[dict[Unknown, Unknown]]) | (((...) -> Any) & Top[list[Unknown]]) | (DataClass_ & Top[list[Unknown]]) | list[Any] | (ListConfig & Top[list[Unknown]]) | (DictConfig & Top[list[Unknown]])`
+ src/hydra_zen/wrapper/_implementations.py:945:16: error[invalid-return-type] Return type does not match returned value: expected `DataClass_ | type[@Todo] | ListConfig | DictConfig`, found `@Todo | DataClass_ | type[@Todo] | ListConfig | DictConfig | (((...) -> Any) & Top[dict[Unknown, Unknown]]) | dict[Any, Any] | (((...) -> Any) & Top[list[Unknown]]) | list[Any]`

pwndbg (https://github.com/pwndbg/pwndbg)
+ pwndbg/commands/__init__.py:758:20: error[invalid-return-type] Return type does not match returned value: expected `T@OnlyWithResolvedHeapSyms | None`, found `((...) -> T@OnlyWithResolvedHeapSyms | None) | None`
+ pwndbg/commands/__init__.py:758:42: error[invalid-argument-type] Argument to function `_try2run_heap_command` is incorrect: Expected `(...) -> (...) -> T@OnlyWithResolvedHeapSyms | None`, found `(...) -> T@OnlyWithResolvedHeapSyms`
+ pwndbg/commands/__init__.py:773:28: error[invalid-return-type] Return type does not match returned value: expected `T@OnlyWithResolvedHeapSyms | None`, found `((...) -> T@OnlyWithResolvedHeapSyms | None) | None`
+ pwndbg/commands/__init__.py:773:50: error[invalid-argument-type] Argument to function `_try2run_heap_command` is incorrect: Expected `(...) -> (...) -> T@OnlyWithResolvedHeapSyms | None`, found `(...) -> T@OnlyWithResolvedHeapSyms`
+ pwndbg/commands/cymbol.py:90:16: error[invalid-return-type] Return type does not match returned value: expected `T@wrapper | None`, found `_OnlyWhenStructFileExists | None`
- Found 2531 diagnostics
+ Found 2536 diagnostics

prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/utilities/asyncutils.py:347:20: error[invalid-return-type] Return type does not match returned value: expected `R@sync_compatible | Coroutine[Any, Any, R@sync_compatible]`, found `(...) -> R@sync_compatible | Coroutine[Any, Any, R@sync_compatible]`
+ src/prefect/utilities/asyncutils.py:351:20: error[invalid-return-type] Return type does not match returned value: expected `R@sync_compatible | Coroutine[Any, Any, R@sync_compatible]`, found `(...) -> R@sync_compatible | Coroutine[Any, Any, R@sync_compatible]`
- Found 3040 diagnostics
+ Found 3042 diagnostics

jax (https://github.com/google/jax)
- jax/_src/pallas/fuser/block_spec.py:933:7: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Unknown]`, found `Sequence[@Todo | int | None] | None`
+ jax/_src/pallas/fuser/block_spec.py:933:7: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[@Todo | int | None]`, found `Sequence[@Todo | int | None] | None`
- jax/_src/pallas/fuser/block_spec.py:963:13: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Unknown]`, found `Sequence[@Todo | int | None] | None`
+ jax/_src/pallas/fuser/block_spec.py:963:13: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[@Todo | int | None]`, found `Sequence[@Todo | int | None] | None`
- jax/_src/pallas/fuser/block_spec.py:1021:18: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Unknown]`, found `Sequence[@Todo | int | None] | None`
+ jax/_src/pallas/fuser/block_spec.py:1021:18: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[@Todo | int | None]`, found `Sequence[@Todo | int | None] | None`
- jax/_src/pallas/fuser/block_spec.py:1568:40: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Unknown]`, found `Sequence[@Todo | int | None] | None`
+ jax/_src/pallas/fuser/block_spec.py:1568:40: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[@Todo | int | None]`, found `Sequence[@Todo | int | None] | None`
- jax/_src/pjit.py:541:44: error[invalid-argument-type] Argument to function `safe_zip` is incorrect: Expected `Iterable[Unknown]`, found `tuple[AbstractValue, ...] | None`
+ jax/_src/pjit.py:541:44: error[invalid-argument-type] Argument to function `safe_zip` is incorrect: Expected `Iterable[AbstractValue]`, found `tuple[AbstractValue, ...] | None`

bokeh (https://github.com/bokeh/bokeh)
- src/bokeh/core/property/alias.py:89:16: error[invalid-return-type] Return type does not match returned value: expected `list[PropertyDescriptor[T@Alias]]`, found `list[Unknown | AliasPropertyDescriptor[Unknown]]`
+ src/bokeh/core/property/alias.py:89:16: error[invalid-return-type] Return type does not match returned value: expected `list[PropertyDescriptor[T@Alias]]`, found `list[PropertyDescriptor[T@Alias] | AliasPropertyDescriptor[Unknown]]`
- src/bokeh/core/property/alias.py:103:16: error[invalid-return-type] Return type does not match returned value: expected `list[PropertyDescriptor[T@DeprecatedAlias]]`, found `list[Unknown | DeprecatedAliasPropertyDescriptor[Unknown]]`
+ src/bokeh/core/property/alias.py:103:16: error[invalid-return-type] Return type does not match returned value: expected `list[PropertyDescriptor[T@DeprecatedAlias]]`, found `list[PropertyDescriptor[T@DeprecatedAlias] | DeprecatedAliasPropertyDescriptor[Unknown]]`
- src/bokeh/core/property/bases.py:184:20: error[invalid-return-type] Return type does not match returned value: expected `T@Property`, found `((() -> T@Property) & ~((...) -> object)) | (T@Property & ~((...) -> object))`
+ src/bokeh/core/property/bases.py:184:20: error[invalid-return-type] Return type does not match returned value: expected `T@Property`, found `T@Property | ((() -> T@Property) & ~((...) -> object))`

ibis (https://github.com/ibis-project/ibis)
- ibis/util.py:112:16: error[invalid-return-type] Return type does not match returned value: expected `list[V@promote_list]`, found `list[Unknown | Top[dict[Unknown, Unknown]]]`
+ ibis/util.py:112:16: error[invalid-return-type] Return type does not match returned value: expected `list[V@promote_list]`, found `list[V@promote_list | Top[dict[Unknown, Unknown]]]`
- ibis/util.py:118:16: error[invalid-return-type] Return type does not match returned value: expected `list[V@promote_list]`, found `list[Unknown | (V@promote_list & ~Top[list[Unknown]] & ~Top[dict[Unknown, Unknown]] & ~None) | (Iterable[V@promote_list] & ~Top[list[Unknown]] & ~Top[dict[Unknown, Unknown]])]`
+ ibis/util.py:118:16: error[invalid-return-type] Return type does not match returned value: expected `list[V@promote_list]`, found `list[V@promote_list | (Iterable[V@promote_list] & ~Top[list[Unknown]] & ~Top[dict[Unknown, Unknown]])]`

dd-trace-py (https://github.com/DataDog/dd-trace-py)
- scripts/freshvenvs.py:230:24: error[invalid-return-type] Return type does not match returned value: expected `tuple[str, list[str]]`, found `tuple[None, list[Unknown]]`
+ scripts/freshvenvs.py:230:24: error[invalid-return-type] Return type does not match returned value: expected `tuple[str, list[str]]`, found `tuple[None, list[str]]`

pandas (https://github.com/pandas-dev/pandas)
- pandas/io/common.py:1167:12: error[invalid-return-type] Return type does not match returned value: expected `tuple[str | BaseBuffer, bool, list[BaseBuffer]]`, found `tuple[_IOWrapper, Literal[True], list[Unknown | _IOWrapper]]`
+ pandas/io/common.py:1167:12: error[invalid-return-type] Return type does not match returned value: expected `tuple[str | BaseBuffer, bool, list[BaseBuffer]]`, found `tuple[_IOWrapper, Literal[True], list[BaseBuffer | _IOWrapper]]`

sympy (https://github.com/sympy/sympy)
+ sympy/matrices/matrixbase.py:3397:16: error[invalid-return-type] Return type does not match returned value: expected `Self@echelon_form | tuple[Self@echelon_form, tuple[int]]`, found `Self@echelon_form | tuple[Self@echelon_form | tuple[Self@echelon_form, tuple[int]] | Unknown, tuple[int]] | Unknown`
+ sympy/matrices/matrixbase.py:3453:16: error[invalid-return-type] Return type does not match returned value: expected `Self@rref | tuple[Self@rref, tuple[int]]`, found `Self@rref | tuple[Self@rref | tuple[Self@rref, tuple[int]] | Unknown, tuple[int]] | Unknown`
+ sympy/matrices/matrixbase.py:3732:16: error[invalid-return-type] Return type does not match returned value: expected `tuple[Tmat@jordan_form, Tmat@jordan_form] | Tmat@jordan_form`, found `tuple[tuple[Tmat@jordan_form, Tmat@jordan_form] | Tmat@jordan_form, tuple[Tmat@jordan_form, Tmat@jordan_form] | Tmat@jordan_form] | Tmat@jordan_form`
- sympy/matrices/matrixbase.py:5501:16: error[invalid-return-type] Return type does not match returned value: expected `Self@pinv_solve`, found `Unknown | None`
+ sympy/matrices/matrixbase.py:5501:16: error[invalid-return-type] Return type does not match returned value: expected `Self@pinv_solve`, found `Self@pinv_solve | Unknown | None`
- Found 13627 diagnostics
+ Found 13630 diagnostics

rotki (https://github.com/rotki/rotki)
+ rotkehlchen/assets/asset.py:172:16: error[invalid-return-type] Return type does not match returned value: expected `AssetWithSymbol`, found `AssetWithNameAndType`
+ rotkehlchen/assets/asset.py:184:16: error[invalid-return-type] Return type does not match returned value: expected `EvmToken`, found `CryptoAsset`
+ rotkehlchen/assets/asset.py:190:16: error[invalid-return-type] Return type does not match returned value: expected `SolanaToken`, found `CryptoAsset`
+ rotkehlchen/assets/asset.py:196:16: error[invalid-return-type] Return type does not match returned value: expected `AssetWithOracles`, found `AssetWithNameAndType`
- rotkehlchen/chain/evm/decoding/beefy_finance/decoder.py:251:16: error[invalid-return-type] Return type does not match returned value: expected `dict[Unknown, str]`, found `dict[Unknown, Literal["beefy_finance"]]`
- rotkehlchen/chain/evm/decoding/compound/v3/decoder.py:407:16: error[invalid-return-type] Return type does not match returned value: expected `dict[Unknown, str]`, found `dict[Unknown, Literal["compound-v3"]]`
- rotkehlchen/chain/evm/decoding/llamazip/decoder.py:81:16: error[invalid-return-type] Return type does not match returned value: expected `dict[Unknown, str]`, found `dict[Unknown, Literal["llamazip"]]`
- rotkehlchen/chain/evm/decoding/morpho/decoder.py:335:16: error[invalid-return-type] Return type does not match returned value: expected `dict[Unknown, str]`, found `dict[Unknown, Literal["morpho"]]`
- rotkehlchen/chain/evm/decoding/uniswap/v3/decoder.py:419:16: error[invalid-return-type] Return type does not match returned value: expected `dict[Unknown, str]`, found `dict[Unknown, Literal["uniswap-v3-router"]]`
- rotkehlchen/chain/evm/decoding/zerox/decoder.py:294:16: error[invalid-return-type] Return type does not match returned value: expected `dict[Unknown, str]`, found `dict[Unknown, Literal["0x"]]`
- rotkehlchen/tests/db/test_db.py:452:20: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `list[EvmToken] | None`
+ rotkehlchen/tests/db/test_db.py:452:20: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[EvmToken]`, found `list[EvmToken] | None`
- Found 1631 diagnostics
+ Found 1629 diagnostics
No memory usage changes detected ✅

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Sep 23, 2025
sharkdp pushed a commit that referenced this pull request Sep 23, 2025
…ith `is_disjoint_from` (#20538)

## Summary

I found this bug while working on #20528.
The minimum reproducible code is:

```python
from __future__ import annotations

from typing import NamedTuple
from ty_extensions import is_disjoint_from, static_assert

class Path(NamedTuple):
    prev: Path | None
    key: str

static_assert(not is_disjoint_from(Path, Path))
```

A stack overflow occurs when a nominal instance type inherits from
`NamedTuple` and is defined recursively.
This PR fixes this bug.

## Test Plan

mdtest updated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ty Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants