Skip to content
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

mypy does not warn about incorrect default value in dict.get in some case #9128

Open
mmohrhard opened this issue Jul 11, 2020 · 1 comment
Open

Comments

@mmohrhard
Copy link

It seems that mypy should actually warn about the assignment of the set in the following code:

from typing import Dict, Any

params: Dict[str, Any] = {}
a: Dict[str, Any] = params.get("abc", set())
reveal_type(a)

mypy does not warn about the incorrect assignment of Set to a but correctly reveals that the type of a is Dict[str, Any]. Sadly the use of Any in this case is common as these dicts represent complex configuration files.

Tested with the current git master version.

@JukkaL
Copy link
Collaborator

JukkaL commented Jul 22, 2020

Yeah, here the inferred type for get could perhaps be more precise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants