Skip to content

[ty] Limit fixed-length tuple expansion in overload matching#23190

Merged
charliermarsh merged 1 commit intomainfrom
charlie/explode
Feb 10, 2026
Merged

[ty] Limit fixed-length tuple expansion in overload matching#23190
charliermarsh merged 1 commit intomainfrom
charlie/explode

Conversation

@charliermarsh
Copy link
Member

Summary

When resolving overloaded calls, ty expands tuple arguments via Cartesian product as required by the spec. This PR adjusts our behavior to match pyright, which limits to 64 types for a single tuple and 256 across. (As-is, we only applied a 512 limit after expanding.)

Closes astral-sh/ty#1870.

@charliermarsh charliermarsh added bug Something isn't working ty Multi-file analysis & type inference labels Feb 9, 2026
@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 9, 2026

Typing conformance results

No changes detected ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 9, 2026

mypy_primer results

Changes were detected when running on open source projects
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 205 diagnostics
+ Found 204 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)`
+ 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/flow_engine.py:1004:32: error[invalid-await] `Unknown | R@FlowRunEngine | Coroutine[Any, Any, R@FlowRunEngine]` is not awaitable
- src/prefect/flow_engine.py:1610:24: error[invalid-await] `Unknown | R@AsyncFlowRunEngine | Coroutine[Any, Any, R@AsyncFlowRunEngine]` is not awaitable
- src/prefect/flow_engine.py:1691: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:1699: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:1733: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:1740:25: warning[possibly-missing-attribute] Attribute `throw` may be missing on object of type `Unknown | R@run_generator_flow_async`
- src/prefect/flows.py:286:34: error[unresolved-attribute] Object of type `(**P@Flow) -> R@Flow` has no attribute `__name__`
+ src/prefect/flows.py:286:34: error[unresolved-attribute] Object of type `((**P@Flow) -> R@Flow) & ((*args: object, **kwargs: object) -> object)` has no attribute `__name__`
- src/prefect/flows.py:404:68: error[unresolved-attribute] Object of type `(**P@Flow) -> R@Flow` has no attribute `__name__`
+ src/prefect/flows.py:404:68: error[unresolved-attribute] Object of type `((**P@Flow) -> R@Flow) & ((*args: object, **kwargs: object) -> object)` has no attribute `__name__`
- src/prefect/flows.py:1946:21: error[no-matching-overload] No overload of function `run_coro_as_sync` matches arguments
+ src/prefect/flows.py:1886:53: warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- Found 5499 diagnostics
+ Found 5493 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

@charliermarsh charliermarsh marked this pull request as ready for review February 9, 2026 23:15
let expanded = per_element
.into_iter()
.multi_cartesian_product()
.map(|types| Type::tuple(TupleType::heterogeneous(db, types)))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.map(|types| Type::tuple(TupleType::heterogeneous(db, types)))
.map(|types| Type::heterogeneous_tuple(db, types))

Copy link
Member Author

Choose a reason for hiding this comment

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

(Oops, will do this in a follow-up commit.)

@AlexWaygood
Copy link
Member

It could be interesting to test whether this helps out with astral-sh/ty#1393 as well

@AlexWaygood AlexWaygood self-assigned this Feb 10, 2026
@charliermarsh charliermarsh merged commit 80a58e2 into main Feb 10, 2026
52 checks passed
@charliermarsh charliermarsh deleted the charlie/explode branch February 10, 2026 00:43
charliermarsh added a commit that referenced this pull request Feb 10, 2026
carljm added a commit to Hugo-Polloli/ruff that referenced this pull request Feb 10, 2026
* main:
  [ty] Fix Pyright links; use `heterogeneous_tuple` (astral-sh#23193)
  [ty] Limit fixed-length tuple expansion in overload matching (astral-sh#23190)
  Fixed import in `runtime-evaluated-decorators` example (astral-sh#23187)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory allocation failure with large tuple operations

2 participants