mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:24:57 +00:00
[ty] fix unpacking a type alias with detailed tuple spec (#19981)
## Summary Fixes https://github.com/astral-sh/ty/issues/1046 We special-case iteration of certain types because they may have a more detailed tuple-spec. Now that type aliases are a distinct type variant, we need to handle them as well. I don't love that `Type::TypeAlias` means we have to remember to add a case for it basically anywhere we are special-casing a certain kind of type, but at the moment I don't have a better plan. It's another argument for avoiding fallback cases in `Type` matches, which we usually prefer; I've updated this match statement to be comprehensive. ## Test Plan Added mdtest.
This commit is contained in:
parent
e6dcdd29f2
commit
a04375173c
2 changed files with 44 additions and 1 deletions
|
@ -64,6 +64,17 @@ x: MyIntOrStr = 1
|
|||
y: MyIntOrStr = None
|
||||
```
|
||||
|
||||
## Unpacking from a type alias
|
||||
|
||||
```py
|
||||
type T = tuple[int, str]
|
||||
|
||||
def f(x: T):
|
||||
a, b = x
|
||||
reveal_type(a) # revealed: int
|
||||
reveal_type(b) # revealed: str
|
||||
```
|
||||
|
||||
## Generic type aliases
|
||||
|
||||
```py
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue