ruff/crates/ty_python_semantic/resources/mdtest/external
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
..
README.md [ty] mdtests with external dependencies (#20904) 2025-12-08 11:44:20 +01:00
attrs.md [ty] mdtests with external dependencies (#20904) 2025-12-08 11:44:20 +01:00
numpy.md [ty] mdtests with external dependencies (#20904) 2025-12-08 11:44:20 +01:00
pydantic.md [ty] mdtests with external dependencies (#20904) 2025-12-08 11:44:20 +01:00
pytest.md [ty] mdtests with external dependencies (#20904) 2025-12-08 11:44:20 +01:00
sqlalchemy.md [ty] Infer type variables within generic unions (#21862) 2025-12-09 16:22:59 +01:00
sqlmodel.md [ty] mdtests with external dependencies (#20904) 2025-12-08 11:44:20 +01:00
strawberry.md [ty] mdtests with external dependencies (#20904) 2025-12-08 11:44:20 +01:00

README.md

mdtests with external dependencies

This directory contains mdtests that make use of external packages. See the mdtest README.md for more information.