ruff/crates/ty_python_semantic/resources/mdtest/generics/legacy
Alex Waygood ec3d5ebda2
[ty] Upcast heterogeneous and mixed tuples to homogeneous tuples where it's necessary to solve a TypeVar (#19635)
## Summary

This PR improves our generics solver such that we are able to solve the
`TypeVar` in this snippet to `int | str` (the union of the elements in
the heterogeneous tuple) by upcasting the heterogeneous tuple to its
pure-homogeneous-tuple supertype:

```py
def f[T](x: tuple[T, ...]) -> T:
    return x[0]

def g(x: tuple[int, str]):
    reveal_type(f(x))
```

## Test Plan

Mdtests. Some TODOs remain in the mdtest regarding solving `TypeVar`s
for mixed tuples, but I think this PR on its own is a significant step
forward for our generics solver when it comes to tuple types.

---------

Co-authored-by: Douglas Creager <dcreager@dcreager.net>
2025-07-30 17:12:21 +01:00
..
classes.md [ty] Don't include already-bound legacy typevars in function generic context (#19558) 2025-07-25 18:14:19 -04:00
functions.md [ty] Upcast heterogeneous and mixed tuples to homogeneous tuples where it's necessary to solve a TypeVar (#19635) 2025-07-30 17:12:21 +01:00
variables.md [ty] Add meta-type tests for legavy TypeVars (#18453) 2025-06-04 07:44:44 +00:00
variance.md [ty] eliminate is_fully_static (#18799) 2025-06-24 18:02:05 -07:00