-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongtopic-inferenceWhen to infer types or require explicit annotationsWhen to infer types or require explicit annotations
Description
Bug Report
Having a code snippet:
dict1 = {"a": 1, "b": "a"}
dict2 = {"c": 1, "d": 2, **dict1}
I receive
error: Argument 1 to "update" of "MutableMapping" has incompatible type "Dict[str, object]"; expected "SupportsKeysAndGetItem[str, int]"
from mypy
To Reproduce
run mypy on the snippet
Expected Behavior
dict1
is Dict[str, object]
and hence dict2
should be and mypy shouldn't raise that.
Actual Behavior
I think this gets analyzed sequentially and so first the dict2
type is inferred from the literal entries and gets set to Dict[str, int]
which then doesn't accept to call an update
using entries from another dict of broader type.
Considering than in Python's syntax this is a single expression - this shouldn't happen like this.
Adding an explicit type to dict2
is a workaround
Your Environment
- Mypy version used: 0.960
- Python version used: 3.9.5
paul-papacz, smarlhens, saartochner-lumigo, haampie, menkotoglou and 14 more
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-inferenceWhen to infer types or require explicit annotationsWhen to infer types or require explicit annotations