Skip to content

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

Merged
merged 4 commits into from
May 22, 2017

Conversation

pkch
Copy link
Contributor

@pkch pkch commented Apr 2, 2017

Fixes #2098

Copy link
Collaborator

@JukkaL JukkaL left a 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
Copy link
Collaborator

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.

Copy link
Contributor Author

@pkch pkch Apr 4, 2017

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).

[case testAugmentedAssignmentIntFloat]
weight0 = 65.5
weight0 = 65
weight0 *= 0.5
Copy link
Collaborator

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 *.

@gvanrossum
Copy link
Member

gvanrossum commented May 10, 2017

I'd love to see this merged. Is there more to it than resolving the merge conflict?

@pkch
Copy link
Contributor Author

pkch commented May 10, 2017

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.

@pkch pkch force-pushed the augmented-assignment branch from 9c8d7eb to 287f415 Compare May 22, 2017 21:37
@gvanrossum gvanrossum merged commit 266a63f into python:master May 22, 2017
@gvanrossum
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants