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
fromtypingimportMappingdeffunc(results: Mapping[str, str]) ->None:
passif__name__=="__main__":
# Passing an int here (even though all values should be strings) is intentionalfunc({"1":"1", "2":2})
Running the above code through mypy gives me the following incorrect error message:
error: List item 1 has incompatible type "Tuple[str, int]"
Strangely enough, the next section of code (which is nearly the same as the above code) produces a better error message:
fromtypingimportMappingdeffunc(results: Mapping[str, str]) ->None:
passif__name__=="__main__":
# Using an int here (even though all values should be strings) is intentionalmy_dict= {"1":"1", "2":2}
func(my_dict)
Running this code through mypy gives the following (better) error message:
error: Argument 1 to "func" has incompatible type Dict[str, object]; expected Mapping[str, str]
My Specs:
Python 3.5.1
mypy-lang 0.4.2
The text was updated successfully, but these errors were encountered:
The examples are a little different from mypy's point of view. In the the first case mypy tries to infer a type for the dictionary expression based on the context where it is used (Mapping[str, str]), and the values don't conform to the context. In the second case mypy infers a type for the dictionary based on no context, so it can give the dictionary are wide enough type. However, this turns out to be incompatible with the function argument later on.
Running the above code through mypy gives me the following incorrect error message:
Strangely enough, the next section of code (which is nearly the same as the above code) produces a better error message:
Running this code through mypy gives the following (better) error message:
My Specs:
Python 3.5.1
mypy-lang 0.4.2
The text was updated successfully, but these errors were encountered: