Skip to content
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

Incompatible dictionary results in confusing error message #1183

Closed
JukkaL opened this issue Jan 28, 2016 · 4 comments
Closed

Incompatible dictionary results in confusing error message #1183

JukkaL opened this issue Jan 28, 2016 · 4 comments
Labels
bug mypy got something wrong priority-0-high

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jan 28, 2016

Dictionary literals with incompatible keys/values result in weird error message, because mypy translate the expression internally to something quite different before type checking.

from typing import Dict
d = {1 : ''} # type: Dict[int, int]

This gives a confusing error message:

t2.py:2: error: List item 0 has incompatible type "Tuple[int, str]"
@JukkaL JukkaL added the bug mypy got something wrong label Jan 28, 2016
@JukkaL JukkaL changed the title Incomptible dictionary results in confusing error message Incompatible dictionary results in confusing error message Jan 28, 2016
@ddfisher ddfisher added this to the 0.3.3 milestone Mar 1, 2016
@fabianhjr
Copy link
Contributor

Ok, this has to do with mypy/messages.py:466: msg = '{} item {} has incompatible type {}'.format(; I will take a look at it. The only thing is that about 20 test cases will need to be changed.

@fabianhjr
Copy link
Contributor

fabianhjr commented Jul 19, 2016

Ok, so this is what I have in mind:

Test if we are dealing with a List[Tuple[Any, Any]] and if so add * NOTE: This might be a Dict to the error message.

Additionally, also add the expected type.

@fabianhjr
Copy link
Contributor

fabianhjr commented Jul 19, 2016

Ok, a fix/imrpovement is ready; It should now read:

t2.py:2: error: List item 0 has incompatible type "Tuple[int, str]"; expected "Tuple[int, int]" * NOTE: This might be a Dict[K, V] instead of List[Tuple[K, V]]

Could you tell me if this is clearer @JukkaL ?

@JukkaL
Copy link
Collaborator Author

JukkaL commented Apr 4, 2017

Fixed by #3100.

@JukkaL JukkaL closed this as completed Apr 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-0-high
Projects
None yet
Development

No branches or pull requests

4 participants