Description
Bug Report
When unpacking a tuple with Union types over existing variables, some of the types disappear.
To Reproduce
import random
def foo() -> tuple[int, None] | tuple[int, str]:
if random.choice((True, False)):
return 0, None
return 5, "thing"
res = None
status, res = foo()
reveal_type(res) # builtins.str
Expected Behavior
res
should be an Optional[str]
, not a str
.
Actual Behavior
The Optional
gets lost in the assignment.
Your Environment
- Mypy version used: 0.950
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini
(and other config files): - Python version used: 3.10
- Operating system and version: Manjaro Linux x86_64 5.15.41-1-MANJARO
This may be related to #9731, but I'm not sure about it.