TypedDict incompatible type message more understandable #10326
Merged
+10
−6
Conversation
|
Hi, can this PR be reviewed? Thanks! |
test-data/unit/check-typeddict.test
Outdated
| @@ -730,7 +730,7 @@ p['x'] = 1 | |||
| from mypy_extensions import TypedDict | |||
| TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int}) | |||
| p = TaggedPoint(type='2d', x=42, y=1337) | |||
| p['x'] = 'y' # E: Argument 2 has incompatible type "str"; expected "int" | |||
| p['x'] = 'y' # E: Argument "x" has incompatible type "str"; expected "int" | |||
TH3CHARLie
Apr 20, 2021
Collaborator
I think the message purposed in the original issue 'Value of "foo" has incompatible type "str"; expected "int"' is more clear since x is not an argument.
Error message for TypedDict more consistent with what was in original issue (#10253)
|
LGTM, let's wait @JukkaL for a final review since error messages are pervasive |
|
OK, let's merge this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.


Description
Added a section to the incompatible_argument function in mypy.messages that is executed when trying to add an incompatible type to a TypedDict. Required adding some imports from mypy.nodes to allow for the isinstance to work.
Fixes #10253
Test Plan
Verified changes with the sample code provided in the issue as well as some other sample TypedDict implementations, below.
Also modified the
testCannotSetItemOfTypedDictWithIncompatibleValueTypetest to check for the new error message.