You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Narrow individual items when matching a tuple to a sequence pattern (#16905)
Fixes#12364
When matching a tuple to a sequence pattern, this change narrows the
type of tuple items inside the matched case:
```py
def test(a: bool, b: bool) -> None:
match a, b:
case True, True:
reveal_type(a) # before: "builtins.bool", after: "Literal[True]"
```
This also works with nested tuples, recursively:
```py
def test(a: bool, b: bool, c: bool) -> None:
match a, (b, c):
case _, [True, False]:
reveal_type(c) # before: "builtins.bool", after: "Literal[False]"
```
This only partially fixes issue #12364; see [my comment
there](#12364 (comment))
for more context.
---
This is my first contribution to mypy, so I may miss some context or
conventions; I'm eager for any feedback!
---------
Co-authored-by: Loïc Simon <[email protected]>
0 commit comments