-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Add expected type in incompatible arg errors #3515
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
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand the pre-release code freeze is over, so that I will merge this when tests pass.
Fixes #3499.