-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongtopic-type-contextType context / bidirectional inferenceType context / bidirectional inferencetopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
Description
Bug Report
To Reproduce
def first() -> None:
tag_name: str | dict[str, str]
if isinstance(tag_name, dict):
tag_name = tag_name.get("foo", "bar")
reveal_type(tag_name)
def second() -> None:
tag_name: str | dict[str, str]
if isinstance(tag_name, dict):
tag_name = tag_name["foo"]
reveal_type(tag_name)
Expected Behavior
str
str
Actual Behavior
Union[str, dict[str, str]]
str
Your Environment
latest mypy
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-type-contextType context / bidirectional inferenceType context / bidirectional inferencetopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder