-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Apparent False Positive With Dict Update Method #5849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I would also appreciate any tips that anyone has on how to properly type annotate highly heterogeneous dictionaries to be used for the purpose of interacting with REST APIs. |
https://mypy.readthedocs.io/en/latest/more_types.html#typeddict The issue itself is valid, and similar to how mypy overreacts to concatenating lists with different types, the latter can be just fixed in typeshed, while this one might require some special-casing. Btw, have you tried giving an explicit annotation to |
Thanks, |
I just came across an interesting variant of this error: class A:
foo: typing.Dict[str, typing.Union[int, str]] = {"a": 1}
class B(A):
# incompatible type "Dict[str, Union[int, str]]"; expected "Mapping[str, str]"
foo = {"b": "c", **A.foo} I assume that what's happening is that the type of the RHS of that assignment is being resolved before mypy is aware that This can be fixed by annotating |
I've stumbled upon the same issue. class Question(typing.TypedDict):
id: str
body: str
question: Question = {
'id': 'something',
'body': 'something else',
}
processed = {
**question,
'documents': []
} Hinting with |
This bug appears to have been fixed. The latest version of mypy doesn't emit an error for any of the above code samples. |
Please provide more information to help us understand the issue:
When I define a somewhat complex and heterogeneous dictionary (meant to later be converted to JSON) it causes mypy to alert me to errors which I do not believe are valid.
Bug
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
Note, this behaviour only occurs when the 'user' input is typed.
I would expect there to be no error for this operation.
Do you see the same issue after installing mypy from Git master?
mypy version 0.641
No flags
The text was updated successfully, but these errors were encountered: