ruff/crates/ty_python_semantic/resources/mdtest/generics/legacy
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
..
classes.md [ty] Carry generic context through when converting class into `Callable` (#21798) 2025-12-05 08:57:21 -05:00
functions.md [ty] Infer type variables within generic unions (#21862) 2025-12-09 16:22:59 +01:00
paramspec.md [ty] Avoid diagnostic when `typing_extensions.ParamSpec` uses `default` parameter (#21839) 2025-12-08 12:34:30 +00:00
variables.md [ty] Support `type[T]` with type variables (#21650) 2025-11-28 09:20:24 +01:00
variance.md [ty] eliminate is_fully_static (#18799) 2025-06-24 18:02:05 -07:00