-
-
Notifications
You must be signed in to change notification settings - Fork 3k
TypedDict incompatible type message more understandable #10326
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
Conversation
|
Hi, can this PR be reviewed? Thanks! |
test-data/unit/check-typeddict.test
Outdated
| 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" |
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 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 (python#10253)
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.
LGTM, let's wait @JukkaL for a final review since error messages are pervasive
|
OK, let's merge this |
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.