-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Treat non-inplace augmented assignment as a simple assignment #3110
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
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.
Looks good, just a few comments about test cases.
@@ -1514,3 +1514,10 @@ class A(): pass | |||
class B(): pass | |||
[out] | |||
main:8: error: Incompatible types in assignment (expression has type "A", variable has type "B") | |||
|
|||
[case testAugmentedAssignmentIntFloat] | |||
weight0 = 65.5 |
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.
Add reveal_type(weight0)
after each assignment.
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.
After I did it, I discovered another problem: I didn't update the binder (the last weight0
should go back to float
, but it stayed as int
in my patch). I have fixed it by using a higher level check_assignment
method instead of copying/pasting a line from check_simple_assignment
. I think this way, the code has become cleaner overall since I could get rid of a couple lines from the original implementation of visit_operator_assignment_stmt
(they are taken care of in the check_assignment
call).
test-data/unit/check-statements.test
Outdated
[case testAugmentedAssignmentIntFloat] | ||
weight0 = 65.5 | ||
weight0 = 65 | ||
weight0 *= 0.5 |
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.
Test also case where there is an error due to invalid operand types for *
.
I'd love to see this merged. Is there more to it than resolving the merge conflict? |
It logically separates augmented assignment into two categories: in-place and not in-place. In the former case, it changes nothing. In the latter case, it makes mypy behave as if augmented assignment was rewritten using a regular assignment. |
9c8d7eb
to
287f415
Compare
Thanks! |
Fixes #2098