Add expected type in incompatible arg errors#3515
Conversation
|
There is one test failing because we are using |
|
I'd start by not adding the "; expected blah" part to the error if format_simple() returns something empty. |
|
Do we really want to do that? Even without this patch mypy prints malformed messages, e.g. (mypy-dev) ~/src/mypy [master] λ cat x.py
from typing import Dict, Callable
def f() -> str:
return 'foo'
d: Dict[str, Callable[..., int]] = {'bar': f}
(mypy-dev) ~/src/mypy [master] λ mypy x.py
x.py:4: error: Dict entry 0 has incompatible type "str":Notice the I'd go for using |
|
Using |
ilevkivskyi
left a comment
There was a problem hiding this comment.
Thanks! This is almost ready to be merged, just two small comments.
|
|
||
| # don't increase verbosity unless there is need to do so | ||
| from mypy.subtypes import is_subtype | ||
| if is_subtype(key_type, expected_key_type): |
There was a problem hiding this comment.
Dict is invariant both in key and value types. Therefore is_subtype is probably not what you want here, maybe is_same_type from sametypes.py?
| expected_value_type_str = self.format(expected_value_type) | ||
| else: | ||
| value_type_str, expected_value_type_str = self.format_distinctly( | ||
| value_type, expected_value_type) |
There was a problem hiding this comment.
I would add few new tests checking that this verbosity logic is followed correctly in different scenarios (taking into account mentioned invariance).
|
@miedzinski After some thinking, it looks like your initial design was actually right and it is OK to use Sorry for troubles. |
ilevkivskyi
left a comment
There was a problem hiding this comment.
As I understand the pre-release code freeze is over, so that I will merge this when tests pass.
Fixes #3499.