ruff/crates
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
..
ruff apply range suppressions to filter diagnostics (#21623) 2025-12-08 16:11:59 -08:00
ruff_annotate_snippets
ruff_benchmark
ruff_cache
ruff_db [ty] Remove legacy concise_message fallback behavior (#21847) 2025-12-08 16:19:01 +00:00
ruff_dev
ruff_diagnostics
ruff_formatter
ruff_graph [ty] Teach ty the meaning of desperation (try ancestor pyproject.tomls as search-paths if module resolution fails) (#21745) 2025-12-03 15:04:36 -05:00
ruff_index
ruff_linter apply range suppressions to filter diagnostics (#21623) 2025-12-08 16:11:59 -08:00
ruff_macros
ruff_memory_usage [ty] Enable LRU collection for parsed module (#21749) 2025-12-03 12:16:18 +01:00
ruff_notebook
ruff_options_metadata
ruff_python_ast Include more details in Tokens 'offset is inside token' panic message (#21860) 2025-12-09 11:12:35 +01:00
ruff_python_ast_integration_tests Add token based parenthesized_ranges implementation (#21738) 2025-12-03 08:15:17 +00:00
ruff_python_codegen
ruff_python_formatter
ruff_python_importer
ruff_python_index
ruff_python_literal
ruff_python_parser [flake8-bugbear] Catch yield expressions within other statements (B901) (#21200) 2025-12-03 12:05:15 -05:00
ruff_python_semantic
ruff_python_stdlib [flake8-bugbear] Accept immutable slice default arguments (B008) (#21823) 2025-12-08 14:00:43 -05:00
ruff_python_trivia
ruff_python_trivia_integration_tests
ruff_server apply range suppressions to filter diagnostics (#21623) 2025-12-08 16:11:59 -08:00
ruff_source_file Use memchr for computing line indexes (#21838) 2025-12-08 08:50:51 -05:00
ruff_text_size
ruff_wasm apply range suppressions to filter diagnostics (#21623) 2025-12-08 16:11:59 -08:00
ruff_workspace
ty [ty] Make Python-version subdiagnostics less verbose (#21849) 2025-12-08 15:58:23 +00:00
ty_combine
ty_completion_eval [ty] Update completion eval to include modules 2025-12-04 17:37:37 -05:00
ty_ide [ty] Stabilize auto-import 2025-12-09 09:40:38 -05:00
ty_project [ty] Enable LRU collection for parsed module (#21749) 2025-12-03 12:16:18 +01:00
ty_python_semantic [ty] Infer type variables within generic unions (#21862) 2025-12-09 16:22:59 +01:00
ty_server [ty] Stabilize auto-import 2025-12-09 09:40:38 -05:00
ty_static
ty_test [ty] Remove legacy concise_message fallback behavior (#21847) 2025-12-08 16:19:01 +00:00
ty_vendored [ty] Carry generic context through when converting class into Callable (#21798) 2025-12-05 08:57:21 -05:00
ty_wasm