Skip to content

[ty] Support constrained TypeVar compatibility across function boundaries#23103

Merged
carljm merged 1 commit intomainfrom
claude/fix-issue-2728-wMAxf
Feb 6, 2026
Merged

[ty] Support constrained TypeVar compatibility across function boundaries#23103
carljm merged 1 commit intomainfrom
claude/fix-issue-2728-wMAxf

Conversation

@carljm
Copy link
Contributor

@carljm carljm commented Feb 5, 2026

Summary

Allow passing constrained TypeVars to functions expecting compatible constrained TypeVars.

Fixes astral-sh/ty#2728

Test Plan

Added mdtests.

Ecosystem results look good. After filtering out non-determinism, it's mostly removing the expected false positives, and then revealing some already-known other issues with constrained typevars as fallout. For example the new scrapy diagnostics are astral-sh/ty#1503.

@AlexWaygood AlexWaygood changed the title Support constrained TypeVar compatibility across function boundaries [ty] Support constrained TypeVar compatibility across function boundaries Feb 5, 2026
@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Feb 5, 2026
@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 5, 2026

Typing conformance results

No changes detected ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 5, 2026

mypy_primer results

Changes were detected when running on open source projects
anyio (https://github.com/agronholm/anyio)
- src/anyio/_core/_fileio.py:201:22: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Argument type `AnyStr@wrap_file` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- Found 90 diagnostics
+ Found 89 diagnostics

pyinstrument (https://github.com/joerick/pyinstrument)
- pyinstrument/util.py:65:30: error[invalid-argument-type] Argument to function `file_is_a_tty` is incorrect: Argument type `AnyStr@file_supports_color` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- Found 43 diagnostics
+ Found 42 diagnostics

pytest (https://github.com/pytest-dev/pytest)
- src/_pytest/capture.py:940:17: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Argument type `AnyStr@CaptureFixture` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- src/_pytest/capture.py:941:17: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Argument type `AnyStr@CaptureFixture` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- src/_pytest/capture.py:968:30: error[invalid-argument-type] Argument is incorrect: Argument type `AnyStr@CaptureFixture` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- src/_pytest/capture.py:968:44: error[invalid-argument-type] Argument is incorrect: Argument type `AnyStr@CaptureFixture` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- Found 399 diagnostics
+ Found 395 diagnostics

scrapy (https://github.com/scrapy/scrapy)
- scrapy/http/headers.py:72:60: error[invalid-argument-type] Argument to bound method `__getitem__` is incorrect: Argument type `AnyStr@__getitem__` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- scrapy/http/headers.py:78:52: error[invalid-argument-type] Argument to bound method `get` is incorrect: Argument type `AnyStr@get` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- scrapy/http/headers.py:84:60: error[invalid-argument-type] Argument to bound method `__getitem__` is incorrect: Argument type `AnyStr@getlist` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- scrapy/http/headers.py:91:9: error[invalid-assignment] Invalid subscript assignment with key of type `AnyStr@setlist` and value of type `Iterable[bytes | str | int]` on object of type `Self@setlist`
- scrapy/http/headers.py:96:32: error[invalid-argument-type] Argument to bound method `setdefault` is incorrect: Argument type `AnyStr@setlistdefault` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- scrapy/http/headers.py:99:28: error[invalid-argument-type] Argument to bound method `getlist` is incorrect: Argument type `AnyStr@appendlist` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- scrapy/http/headers.py:101:9: error[invalid-assignment] Invalid subscript assignment with key of type `AnyStr@appendlist` and value of type `list[bytes]` on object of type `Self@appendlist`
- scrapy/utils/datatypes.py:56:52: error[invalid-argument-type] Argument to bound method `normkey` is incorrect: Argument type `AnyStr@__getitem__` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- scrapy/utils/datatypes.py:59:45: error[invalid-argument-type] Argument to bound method `normkey` is incorrect: Argument type `AnyStr@__setitem__` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- scrapy/utils/datatypes.py:62:45: error[invalid-argument-type] Argument to bound method `normkey` is incorrect: Argument type `AnyStr@__delitem__` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- scrapy/utils/datatypes.py:65:53: error[invalid-argument-type] Argument to bound method `normkey` is incorrect: Argument type `AnyStr@__contains__` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- scrapy/utils/datatypes.py:83:44: error[invalid-argument-type] Argument to bound method `normkey` is incorrect: Argument type `AnyStr@get` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- scrapy/utils/datatypes.py:99:44: error[invalid-argument-type] Argument to bound method `normkey` is incorrect: Argument type `AnyStr@pop` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- scrapy/utils/datatypes.py:112:40: error[invalid-argument-type] Argument to bound method `_normkey` is incorrect: Argument type `AnyStr@__getitem__` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
+ scrapy/utils/datatypes.py:96:47: warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ scrapy/utils/datatypes.py:113:47: error[invalid-argument-type] Argument to bound method `lower` is incorrect: Expected `bytes`, found `AnyStr@__getitem__`
+ scrapy/utils/datatypes.py:113:47: error[no-matching-overload] No overload of bound method `lower` matches arguments
- scrapy/utils/datatypes.py:116:40: error[invalid-argument-type] Argument to bound method `_normkey` is incorrect: Argument type `AnyStr@__setitem__` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- scrapy/utils/datatypes.py:126:40: error[invalid-argument-type] Argument to bound method `_normkey` is incorrect: Argument type `AnyStr@__delitem__` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
+ scrapy/utils/datatypes.py:118:36: error[invalid-argument-type] Argument to bound method `lower` is incorrect: Expected `bytes`, found `AnyStr@__setitem__`
+ scrapy/utils/datatypes.py:118:36: error[no-matching-overload] No overload of bound method `lower` matches arguments
+ scrapy/utils/datatypes.py:123:20: error[invalid-argument-type] Argument to bound method `lower` is incorrect: Expected `bytes`, found `AnyStr@__setitem__`
+ scrapy/utils/datatypes.py:123:20: error[no-matching-overload] No overload of bound method `lower` matches arguments
+ scrapy/utils/datatypes.py:127:37: error[invalid-argument-type] Argument to bound method `lower` is incorrect: Expected `bytes`, found `AnyStr@__delitem__`
+ scrapy/utils/datatypes.py:127:37: error[no-matching-overload] No overload of bound method `lower` matches arguments
- scrapy/utils/datatypes.py:131:40: error[invalid-argument-type] Argument to bound method `_normkey` is incorrect: Argument type `AnyStr@__contains__` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
+ scrapy/utils/datatypes.py:132:16: error[invalid-argument-type] Argument to bound method `lower` is incorrect: Expected `bytes`, found `AnyStr@__contains__`
+ scrapy/utils/datatypes.py:132:16: error[no-matching-overload] No overload of bound method `lower` matches arguments
- Found 1786 diagnostics
+ Found 1780 diagnostics

porcupine (https://github.com/Akuli/porcupine)
- porcupine/pluginmanager.py:133:49: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Never]`, found `Unknown | str`
- Found 25 diagnostics
+ Found 24 diagnostics

pydantic (https://github.com/pydantic/pydantic)
- pydantic/_internal/_validators.py:174:16: error[no-matching-overload] No overload of function `compile` matches arguments
- Found 3154 diagnostics
+ Found 3153 diagnostics

mitmproxy (https://github.com/mitmproxy/mitmproxy)
- mitmproxy/net/http/url.py:147:21: error[invalid-argument-type] Argument to function `default_port` is incorrect: Argument type `AnyStr@hostport` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- test/mitmproxy/net/http/test_url.py:193:28: error[invalid-argument-type] Argument to function `parse_authority` is incorrect: Argument type `AnyStr@test_parse_authority` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- test/mitmproxy/net/http/test_url.py:196:32: error[invalid-argument-type] Argument to function `parse_authority` is incorrect: Argument type `AnyStr@test_parse_authority` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- test/mitmproxy/net/http/test_url.py:199:29: error[invalid-argument-type] Argument to function `parse_authority` is incorrect: Argument type `AnyStr@test_parse_authority` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- Found 2128 diagnostics
+ Found 2124 diagnostics

Expression (https://github.com/cognitedata/Expression)
- tests/test_compose.py:21:16: error[invalid-assignment] Object of type `(Never, /) -> Never` is not assignable to `(int, /) -> int`
- Found 201 diagnostics
+ Found 200 diagnostics

koda-validate (https://github.com/keithasaurus/koda-validate)
- koda_validate/generic.py:152:56: error[invalid-argument-type] Argument is incorrect: Argument type `ExactMatchT@EqualsValidator` does not satisfy constraints (`bool`, `bytes`, `int`, `Decimal`, `str`, `int | float`, `date`, `datetime`, `UUID`) of type variable `ExactMatchT`
- Found 400 diagnostics
+ Found 399 diagnostics

mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
- bson/regex.py:133:16: error[no-matching-overload] No overload of function `compile` matches arguments
- Found 443 diagnostics
+ Found 442 diagnostics

cibuildwheel (https://github.com/pypa/cibuildwheel)
- cibuildwheel/logger.py:409:30: error[invalid-argument-type] Argument to function `file_is_a_tty` is incorrect: Argument type `AnyStr@file_supports_color` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- Found 30 diagnostics
+ Found 29 diagnostics

meson (https://github.com/mesonbuild/meson)
- mesonbuild/cargo/builder.py:33:72: error[invalid-argument-type] Argument is incorrect: Argument type `TV_TokenTypes@_token` does not satisfy constraints (`int`, `str`, `bool`) of type variable `TV_TokenTypes`
- Found 2188 diagnostics
+ Found 2187 diagnostics

trio (https://github.com/python-trio/trio)
- src/trio/_file_io.py:269:22: error[invalid-argument-type] Argument to bound method `readline` is incorrect: Argument type `AnyStr@__anext__` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- Found 472 diagnostics
+ Found 471 diagnostics

xarray (https://github.com/pydata/xarray)
- xarray/core/_typed_ops.py:1447:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__add__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1450:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__sub__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1453:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__mul__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1456:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__pow__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1459:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__truediv__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1462:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__floordiv__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1465:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__mod__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1468:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__and__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1471:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__xor__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1474:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__or__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1477:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__lshift__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1480:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__rshift__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1483:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__lt__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1486:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__le__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1489:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__gt__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1492:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__ge__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1495:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__eq__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1498:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__ne__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1505:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__radd__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1508:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__rsub__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1511:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__rmul__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1514:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__rpow__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1517:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__rtruediv__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1520:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__rfloordiv__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1523:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__rmod__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1526:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__rand__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1529:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__rxor__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/_typed_ops.py:1532:32: error[invalid-argument-type] Argument to bound method `_binary_op` is incorrect: Argument type `T_Xarray@__ror__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/dataarray.py:2556:13: error[invalid-argument-type] Argument to bound method `interp_like` is incorrect: Argument type `T_Xarray@interp_like` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/dataarray.py:4868:25: error[invalid-argument-type] Argument to bound method `dot` is incorrect: Argument type `T_Xarray@__matmul__` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/core/indexing.py:206:48: error[invalid-argument-type] Argument to function `group_indexers_by_index` is incorrect: Argument type `T_Xarray@map_index_queries` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- xarray/tests/test_indexing.py:169:50: error[invalid-argument-type] Argument to function `map_index_queries` is incorrect: Argument type `T_Xarray@test_indexer` does not satisfy constraints (`DataArray`, `Dataset`) of type variable `T_Xarray`
- Found 1746 diagnostics
+ Found 1714 diagnostics

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/deployments/runner.py:1017:70: warning[possibly-missing-attribute] Attribute `__name__` may be missing on object of type `Unknown | (((...) -> Any) & ((*args: object, **kwargs: object) -> object))`
+ src/prefect/deployments/runner.py:1017:70: warning[possibly-missing-attribute] Attribute `__name__` may be missing on object of type `Unknown | ((...) -> Any)`
+ src/prefect/flow_engine.py:997:32: error[invalid-await] `Unknown | R@FlowRunEngine | Coroutine[Any, Any, R@FlowRunEngine]` is not awaitable
+ src/prefect/flow_engine.py:1596:24: error[invalid-await] `Unknown | R@AsyncFlowRunEngine | Coroutine[Any, Any, R@AsyncFlowRunEngine]` is not awaitable
+ src/prefect/flow_engine.py:1677:43: error[invalid-argument-type] Argument to function `next` is incorrect: Expected `SupportsNext[Unknown]`, found `Unknown | R@run_generator_flow_sync`
+ src/prefect/flow_engine.py:1685:21: warning[possibly-missing-attribute] Attribute `throw` may be missing on object of type `Unknown | R@run_generator_flow_sync`
+ src/prefect/flow_engine.py:1719:44: warning[possibly-missing-attribute] Attribute `__anext__` may be missing on object of type `Unknown | R@run_generator_flow_async`
+ src/prefect/flow_engine.py:1726:25: warning[possibly-missing-attribute] Attribute `throw` may be missing on object of type `Unknown | R@run_generator_flow_async`
- src/prefect/flows.py:285:34: error[unresolved-attribute] Object of type `((**P@Flow) -> R@Flow) & ((*args: object, **kwargs: object) -> object)` has no attribute `__name__`
+ src/prefect/flows.py:285:34: error[unresolved-attribute] Object of type `(**P@Flow) -> R@Flow` has no attribute `__name__`
- src/prefect/flows.py:403:68: error[unresolved-attribute] Object of type `((**P@Flow) -> R@Flow) & ((*args: object, **kwargs: object) -> object)` has no attribute `__name__`
+ src/prefect/flows.py:403:68: error[unresolved-attribute] Object of type `(**P@Flow) -> R@Flow` has no attribute `__name__`
- src/prefect/flows.py:1885:53: warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ src/prefect/flows.py:1945:21: error[no-matching-overload] No overload of function `run_coro_as_sync` matches arguments
- src/prefect/input/run_input.py:672:20: error[invalid-return-type] Return type does not match returned value: expected `T@GetAutomaticInputHandler | AutomaticRunInput[T@GetAutomaticInputHandler]`, found `T@GetAutomaticInputHandler | AutomaticRunInput[T@GetAutomaticInputHandler] | Coroutine[Any, Any, T@GetAutomaticInputHandler | AutomaticRunInput[T@GetAutomaticInputHandler]]`
+ src/prefect/input/run_input.py:672:20: error[invalid-return-type] Return type does not match returned value: expected `T@GetAutomaticInputHandler | AutomaticRunInput[T@GetAutomaticInputHandler]`, found `Unknown | Coroutine[Any, Any, Unknown]`
- Found 5456 diagnostics
+ Found 5462 diagnostics

setuptools (https://github.com/pypa/setuptools)
- setuptools/_distutils/util.py:157:25: error[no-matching-overload] No overload of function `splitdrive` matches arguments
+ setuptools/_distutils/util.py:158:12: error[invalid-argument-type] Method `__getitem__` of type `(Overload[(key: SupportsIndex | slice[SupportsIndex | None, SupportsIndex | None, SupportsIndex | None], /) -> LiteralString, (key: SupportsIndex | slice[SupportsIndex | None, SupportsIndex | None, SupportsIndex | None], /) -> str]) | (Overload[(key: SupportsIndex, /) -> int, (key: slice[SupportsIndex | None, SupportsIndex | None, SupportsIndex | None], /) -> bytes])` cannot be called with key of type `Literal[0]` on object of type `AnyStr@change_root`
+ setuptools/_distutils/util.py:159:20: error[invalid-argument-type] Method `__getitem__` of type `(Overload[(key: SupportsIndex | slice[SupportsIndex | None, SupportsIndex | None, SupportsIndex | None], /) -> LiteralString, (key: SupportsIndex | slice[SupportsIndex | None, SupportsIndex | None, SupportsIndex | None], /) -> str]) | (Overload[(key: SupportsIndex, /) -> int, (key: slice[SupportsIndex | None, SupportsIndex | None, SupportsIndex | None], /) -> bytes])` cannot be called with key of type `slice[Literal[1], None, None]` on object of type `AnyStr@change_root`
- setuptools/glob.py:34:23: error[invalid-argument-type] Argument to function `iglob` is incorrect: Argument type `AnyStr@glob` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- setuptools/glob.py:48:17: error[invalid-argument-type] Argument to function `_iglob` is incorrect: Argument type `AnyStr@iglob` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
- setuptools/glob.py:56:25: error[no-matching-overload] No overload of function `split` matches arguments
+ setuptools/glob.py:70:20: error[no-matching-overload] No overload of function `glob2` matches arguments
+ setuptools/glob.py:70:20: error[no-matching-overload] No overload of function `glob1` matches arguments
+ setuptools/glob.py:75:42: error[invalid-argument-type] Argument to function `has_magic` is incorrect: Expected `str | bytes`, found `AnyStr@_iglob & ~AlwaysFalsy`
- Found 1139 diagnostics
+ Found 1140 diagnostics

scikit-build-core (https://github.com/scikit-build/scikit-build-core)
- src/scikit_build_core/build/wheel.py:99:20: error[no-matching-overload] No overload of bound method `__init__` matches arguments
- Found 50 diagnostics
+ Found 49 diagnostics

materialize (https://github.com/MaterializeInc/materialize)
- misc/python/materialize/cli/mz_workload_anonymize.py:251:13: error[no-matching-overload] No overload of bound method `join` matches arguments
- Found 535 diagnostics
+ Found 534 diagnostics

sympy (https://github.com/sympy/sympy)
- sympy/matrices/eigen.py:1202:37: error[unresolved-attribute] Object of type `T2'return@call_highest_priority | T1'return@call_highest_priority` has no attribute `pow`
+ sympy/matrices/eigen.py:1202:37: error[unresolved-attribute] Object of type `T1'return@call_highest_priority | T2'return@call_highest_priority` has no attribute `pow`
- sympy/matrices/matrixbase.py:2957:16: error[invalid-return-type] Return type does not match returned value: expected `Self@_eval_pow_by_cayley`, found `Self@_eval_pow_by_cayley | T2'return@call_highest_priority | T1'return@call_highest_priority`
+ sympy/matrices/matrixbase.py:2957:16: error[invalid-return-type] Return type does not match returned value: expected `Self@_eval_pow_by_cayley`, found `Self@_eval_pow_by_cayley | T1'return@call_highest_priority | T2'return@call_highest_priority`
- sympy/matrices/matrixbase.py:3256:16: error[invalid-return-type] Return type does not match returned value: expected `MatrixBase`, found `T2'return@call_highest_priority | T1'return@call_highest_priority`
+ sympy/matrices/matrixbase.py:3256:16: error[invalid-return-type] Return type does not match returned value: expected `MatrixBase`, found `T1'return@call_highest_priority | T2'return@call_highest_priority`
- sympy/matrices/matrixbase.py:3256:29: error[invalid-argument-type] Argument is incorrect: Expected `T2'return@call_highest_priority | T1'return@call_highest_priority`, found `MatrixBase`
+ sympy/matrices/matrixbase.py:3256:29: error[invalid-argument-type] Argument is incorrect: Expected `T1'return@call_highest_priority | T2'return@call_highest_priority`, found `MatrixBase`
- sympy/matrices/matrixbase.py:4923:16: error[invalid-return-type] Return type does not match returned value: expected `Self@analytic_func`, found `Self@analytic_func | T2'return@call_highest_priority | T1'return@call_highest_priority`
+ sympy/matrices/matrixbase.py:4923:16: error[invalid-return-type] Return type does not match returned value: expected `Self@analytic_func`, found `Self@analytic_func | T1'return@call_highest_priority | T2'return@call_highest_priority`

jax (https://github.com/google/jax)
- jax/_src/pallas/mosaic_gpu/lowering.py:1512:10: error[invalid-return-type] Return type does not match returned value: expected `tuple[RefOrTmemType@_handle_transforms, Sequence[Transform]]`, found `tuple[Unknown | MultimemRef, list[Unknown]]`
+ jax/_src/pallas/mosaic_gpu/lowering.py:1512:10: error[invalid-return-type] Return type does not match returned value: expected `tuple[RefOrTmemType@_handle_transforms, Sequence[Transform]]`, found `tuple[RefOrTmemType@_handle_transforms | TMEMRef | Unknown | MultimemRef, list[Unknown]]`

No memory usage changes detected ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 5, 2026

ecosystem-analyzer results

Lint rule Added Removed Changed
unsupported-operator 0 89 40
not-subscriptable 1 96 0
invalid-argument-type 13 63 7
possibly-missing-attribute 22 3 35
no-matching-overload 27 4 0
invalid-return-type 1 0 4
invalid-assignment 0 2 1
not-iterable 0 0 2
unused-type-ignore-comment 1 0 0
Total 65 257 89

Full report with detailed diff (timing results)

@carljm carljm marked this pull request as ready for review February 6, 2026 01:40
@carljm carljm force-pushed the claude/fix-issue-2728-wMAxf branch 2 times, most recently from 60c6c18 to 3139d4d Compare February 6, 2026 02:54
@carljm carljm marked this pull request as draft February 6, 2026 03:06
@carljm

This comment was marked as outdated.

…y each other

When a constrained TypeVar is passed to a function expecting another constrained
TypeVar, check whether each constraint of the actual TypeVar is assignable to at
least one constraint of the formal TypeVar. This fixes false-positive errors when
wrapping functions from external packages that define private TypeVars with the
same (or compatible) constraint sets.

Fixes astral-sh/ty#2728

https://claude.ai/code/session_01FbdSnWQPg9EZgcwbR5Kujp
@carljm carljm force-pushed the claude/fix-issue-2728-wMAxf branch from 3139d4d to cc5ee4b Compare February 6, 2026 03:10
@carljm carljm marked this pull request as ready for review February 6, 2026 03:14
Comment on lines +1052 to +1053
strict subtype would be unsound. For example, a function constrained to `(int, str)` may narrow `T`
to `int` and return `int(x)`, which would violate a caller's `bool` constraint:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it, really? It looks like we don't support that. We don't even support return x, which definitely seems wrong.

https://play.ty.dev/f42eaa69-07d0-42ff-b641-750fedf2ed84

Copy link
Contributor Author

@carljm carljm Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this analysis of what is sound or not is not based on how we currently narrow constrained typevars, but on how other type checkers do it and how I believe we should do it after fixing astral-sh/ty#1475. I don't want to add behavior here that will become unsound when that issue is fixed. I can add a parenthetical here clarifying that if you think it's needed, although I kind of preferred not to since it's just one more thing we'll have to remember to find and update when fixing that issue (and there's a good chance we won't remember and it'll stay as an obsolete parenthetical.)

I do think it is correct for a type-checker to allow if isinstance(x, int): return int(x) where x is typed as a typevar constrained to (int, something). Constrained typevars must solve to one of the constrained types -- if you verify it is solved to int, the caller may not expect any more precise type than exactly int.

Pyright, pyrefly, and mypy are all fine with that narrowing inside the body of f. Pyright and pyrefly also allow the call from g, which is not sound. Mypy has the behavior I think we want (allow the narrowing in f, disallow the call from g with subtype constraints -- but allow it if the constraints match exactly.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I hadn't seen astral-sh/ty#1475

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ecosystem-analyzer ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

a constrained TypeVar should be assignable to another constrained TypeVar with a superset of its constraints

5 participants