Description
Feature
This could also be classified as a bug report, but it's also a feature request. Consider code like this:
from typing import Any, Optional
def test(**kwargs):
...
kwargs: Optional[Any]
test(**kwargs)
Now, this is obviously wrong on purpose, and in latest MyPy, results in this error message:
error: Argument after ** must be a mapping
The problem with this message is that, it doesn't say what exactly is wrong, unlike when you normally mismatch types where it says: Argument 1 to "test" has incompatible type "Union[int, str]"; expected "bool"
, for example. In my case, I had a variable with the same name inferring Optional[Any]
higher up in the code, and tracking down the root cause took me good 10 minutes,
Pitch
Even though **kwargs
usage like this is uncommon, having a similarly improved message would help with debugging why this may be happening. Something like: Argument after ** to "test" has incompatible type "Union[Any, None]", expected "Mapping[str, Any]"
should help a lot.