-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Labels
bugmypy got something wrongmypy got something wrongpriority-0-hightopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
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.strExpected 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.
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongpriority-0-hightopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder