-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codepriority-1-normaltopic-join-v-unionUsing join vs. using unionsUsing join vs. using unionstopic-ternary-expressiona if b else ca if b else c
Description
- Are you reporting a bug, or opening a feature request?
Bug
- Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private.
from typing import Dict
from dataclasses import dataclass
@dataclass
class Foo:
bar: bool
@dataclass
class Bar:
baz: bool
foo_registry: Dict[str, Foo] = {}
bar_registry: Dict[str, Bar] = {}
use_foo = True
registry = foo_registry if use_foo else bar_registry
registry.get('asdfsdf')
- What is the actual behavior/output?
On the last line, mypy infers that registry
has the type object
error: "object" has no attribute "get"
- What is the behavior/output you expect?
mypy infers that the type of registry
to be Union[Dict[str, Foo], Dict[str, Bar]]
but it looks like this behavior may have been undone by #5095 ?
- What are the versions of mypy and Python you are using?
mypy 0.740 and Python 3.7.2
Do you see the same issue after installing mypy from Git master?
I ran into other issues doing this, but I am on the latest release.
- What are the mypy flags you are using? (For example --strict-optional)
I'm using --strict --warn-unreachable
though this occurs with no flags at all.
Thanks for reading.
mplanchard and jgillard
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codepriority-1-normaltopic-join-v-unionUsing join vs. using unionsUsing join vs. using unionstopic-ternary-expressiona if b else ca if b else c