ruff/crates/ty_python_semantic/resources/mdtest/generics/pep695
David Peter aea2bc2308
[ty] Infer type variables within generic unions (#21862)
## Summary

This PR allows our generics solver to find a solution for `T` in cases
like the following:
```py
def extract_t[T](x: P[T] | Q[T]) -> T:
    raise NotImplementedError

reveal_type(extract_t(P[int]()))  # revealed: int
reveal_type(extract_t(Q[str]()))  # revealed: str
```

closes https://github.com/astral-sh/ty/issues/1772
closes https://github.com/astral-sh/ty/issues/1314

## Ecosystem

The impact here looks very good!

It took me a long time to figure this out, but the new diagnostics on
bokeh are actually true positives. I should have tested with another
type-checker immediately, I guess. All other type checkers also emit
errors on these `__init__` calls. MRE
[here](https://play.ty.dev/5c19d260-65e2-4f70-a75e-1a25780843a2) (no
error on main, diagnostic on this branch)

A lot of false positives on home-assistant go away for calls to
functions like
[`async_listen`](180053fe98/homeassistant/core.py (L1581-L1587))
which take a `event_type: EventType[_DataT] | str` parameter. We can now
solve for `_DataT` here, which was previously falling back to its
default value, and then caused problems because it was used as an
argument to an invariant generic class.

## Test Plan

New Markdown tests
2025-12-09 16:22:59 +01:00
..
aliases.md [ty] Complete support for `ParamSpec` (#21445) 2025-12-05 22:00:06 +05:30
classes.md [ty] Complete support for `ParamSpec` (#21445) 2025-12-05 22:00:06 +05:30
functions.md [ty] Infer type variables within generic unions (#21862) 2025-12-09 16:22:59 +01:00
paramspec.md [ty] Handle various invalid explicit specializations for `ParamSpec` (#21821) 2025-12-08 05:20:41 +00:00
variables.md [ty] Support `type[T]` with type variables (#21650) 2025-11-28 09:20:24 +01:00
variance.md [ty] impl `VarianceInferable` for `KnownInstanceType` (#20924) 2025-10-17 21:12:19 +02:00