Skip to content
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

Fix non commutative operators (__rsub__, __rdiv__) #123

Merged

Conversation

lieryan
Copy link

@lieryan lieryan commented Nov 28, 2019

Previously, doing operations like 0 - Money(5) or 5 / Money(2) will silently produce buggy results, as these operations have been implemented to be equivalent to their forward operations. As these operations are not commutative, the result was incorrect.

With this PR, doing these operations raises TypeError instead, as doing those operations usually don't really make much sense.

Lie Ryan added 2 commits November 28, 2019 19:48
Previously, the expression 0 - Money(5, 'USD') would have returned
Money(5, 'USD'), which was incorrect and unexpected, as the correct
answer should've been Money(-5, 'USD')
Previously, division operations like 5 / Money(10, 'USD') would've given
an incorrect result (2 instead of 0.5). Now, this operation raises a
TypeError instead, as dividing non-Money by Money makes no sense
dimension-wise.
@spookylukey
Copy link
Collaborator

Thanks for PR. Build was broken on master, but is fixed now. Could you merge from master so that the CI will run again?

@lieryan
Copy link
Author

lieryan commented Dec 2, 2019

Thanks for fixing master, I've updated my branch against master and the CI should be passing now.

@spookylukey spookylukey merged commit 796a7ec into py-moneyed:master Dec 2, 2019
@spookylukey
Copy link
Collaborator

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.

2 participants