[ty] Implicit type aliases: Support for PEP 604 unions (#21195)

## Summary

Add support for implicit type aliases that use PEP 604 unions:
```py
IntOrStr = int | str

reveal_type(IntOrStr)  # UnionType

def _(int_or_str: IntOrStr):
    reveal_type(int_or_str)  # int | str
```

## Typing conformance

The changes are either removed false positives, or new diagnostics due
to known limitations unrelated to this PR.

## Ecosystem impact

Spot checked, a mix of true positives and known limitations.

## Test Plan

New Markdown tests.
This commit is contained in:
David Peter 2025-11-03 21:50:25 +01:00 committed by GitHub
parent fe4ee81b97
commit 1fe958c694
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 334 additions and 36 deletions

View file

@ -72,9 +72,6 @@ def f(x: Union) -> None:
## Implicit type aliases using new-style unions
We don't recognize these as type aliases yet, but we also don't emit false-positive diagnostics if
you use them in type expressions:
```toml
[environment]
python-version = "3.10"
@ -84,5 +81,5 @@ python-version = "3.10"
X = int | str
def f(y: X):
reveal_type(y) # revealed: @Todo(Support for `types.UnionType` instances in type expressions)
reveal_type(y) # revealed: int | str
```