ruff
54acbcde - [ty] Support `TypeVarTuple` and `Unpack` (#25240)

Commit
28 days ago
[ty] Support `TypeVarTuple` and `Unpack` (#25240) ## Summary closes: astral-sh/ty#156 closes: astral-sh/ty#1746 This PR adds initial support for `TypeVarTuple` and `Unpack` in ty. ### Supported - Legacy `TypeVarTuple(...)` definitions from `typing` and `typing_extensions`, including defaults, variance, and version validation. - PEP 695 `[*Ts]`, `Unpack[...]`, and starred unpack forms, with diagnostics for invalid uses. - Explicit specialization and substitution for generic classes and aliases. - Fixed and variable-length tuple construction, relations, display, hover, and goto-type-definition. - Legacy-solver inference from tuple arguments and returns, constructors, and positional callable signatures. - A `ParamSpec` following an unpacked variadic prefix. ### Representation and inference A `TypeVarTuple` occupies one generic specialization slot and is represented by a `TupleType`. Tuple specifications preserve a fixed prefix and suffix around a variable middle and an unresolved / invalid `TypeVarTuple` resolves as `tuple[Unknown, ...]`. Callable inference constructs `ConstraintSet`s while matching positional parameters in the signature relation. This keeps callable compatibility and inference in the same loop instead of adding a separate TypeVarTuple-specific path to `SpecializationBuilder`. The work was briefly split into a [type-form foundation](https://github.com/astral-sh/ruff/pull/26126) and generic logic PR. I recombined them because the foundation alone caused conformance and ecosystem regressions and did not represent complete, independently reviewable behavior. ### Deliberate follow-ups Call binding does not yet aggregate arguments matched to `*args` into a `tuple`, or validate calls against concrete unpacked tuple annotations. Per-argument inference is skipped because it would create incorrect scalar mappings. Nested tuple unpacking in callable parameter lists and some correlations involving generic, overloaded, union, and inherited callables also remain follow-ups. The ecosystem results show these callable cases account for the main remaining false positives. ## Test Plan - Added shared semantic coverage to the PEP 695 tests. - Added legacy definition and specialization coverage. - Kept the standalone `Unpack` coverage focused on its distinct syntax paths. - Reviewed the semantic suite, conformance results, and ecosystem changes.
Author
Parents
Loading