KEMBAR78
Treat non-inplace augmented assignment as a simple assignment by pkch · Pull Request #3110 · python/mypy · GitHub
Skip to content

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.

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