You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
foo.py:7: error: Argument 1 to "diff_types" has incompatible type **Dict[str, object]; expected "int"
foo.py:7: error: Argument 1 to "diff_types" has incompatible type **Dict[str, object]; expected "str"
adding a generic type like this params = dict(foo=1, bar='bar') # type: dict solves the issue.
Changing the function's signature to have both params the same type (eg. str) (+ changing the params accordingly) obviously solves the issue.
Would it be possible to make it work without explicitly specifying the # type: dict there?
Cheers.
mypy version 0.521
The text was updated successfully, but these errors were encountered:
The annotation solves the issue since # type: dict is equivalent to # type: Dict[Any, Any]. Mypy doesn't infer this type automatically since mypy let's you do anything with Any values, which potentially causes mypy to miss some real errors in your code. The inferred type Dict[str, object] is technically correct and type safe, but typically not very useful.
There is a clear usability problem. A potential way to improve the situation would be to explicitly require an annotation for params. I created a new issue #3816 for this. Closing this issue since the current behavior is technically correct, even if it's confusing.
Hi,
not sure if I got it right, but it looks like the type of dict in example below is incorrectly inferred:
output for
mypy --py2 ./foo.py
adding a generic type like this
params = dict(foo=1, bar='bar') # type: dict
solves the issue.Changing the function's signature to have both params the same type (eg.
str
) (+ changing the params accordingly) obviously solves the issue.Would it be possible to make it work without explicitly specifying the
# type: dict
there?Cheers.
mypy version 0.521
The text was updated successfully, but these errors were encountered: