mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-20 04:29:47 +00:00
[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:
parent
fe4ee81b97
commit
1fe958c694
13 changed files with 334 additions and 36 deletions
|
|
@ -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
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue