Bug Report
Matching a tuple literal against a type which is a tuple literal unioned with another value gives incorrect types for the matched values. They will each be the union of the tuple fields instead of being the correct position
To Reproduce
x: tuple[int, str] | None = (1, "hi")
match x:
case (a, b):
reveal_type(a)
reveal_type(b)
Expected Behavior
main.py:4: note: Revealed type is "builtins.int"
main.py:5: note: Revealed type is "builtins.str"
Success: no issues found in 1 source file
Actual Behavior
main.py:4: note: Revealed type is "builtins.int | builtins.str"
main.py:5: note: Revealed type is "builtins.int | builtins.str"
Success: no issues found in 1 source file
Other Working Examples
If I remove the union, then it works properly:
x: tuple[int, str] = (1, "hi")
match x:
case (a, b):
reveal_type(a)
reveal_type(b)
main.py:4: note: Revealed type is "builtins.int"
main.py:5: note: Revealed type is "builtins.str"
Success: no issues found in 1 source file
Or if I handle the None case first, so the union is narrowed:
x: tuple[int, str] | None = (1, "hi")
match x:
case None: pass
case (a, b):
reveal_type(a)
reveal_type(b)
main.py:5: note: Revealed type is "builtins.int"
main.py:6: note: Revealed type is "builtins.str"
Success: no issues found in 1 source file
Your Environment
MyPy Playground, tested against master and 1.17.0
Bug Report
Matching a tuple literal against a type which is a tuple literal unioned with another value gives incorrect types for the matched values. They will each be the union of the tuple fields instead of being the correct position
To Reproduce
Expected Behavior
Actual Behavior
Other Working Examples
If I remove the union, then it works properly:
Or if I handle the
Nonecase first, so the union is narrowed:Your Environment
MyPy Playground, tested against master and 1.17.0