Skip to content

Commit

Permalink
backport __rtruediv__ behaviour from current py-moneyed master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
wearebasti authored and Stranger6667 committed Dec 29, 2020
1 parent 5b9cde3 commit 2b3d0a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion djmoney/money.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ def __truediv__(self, other):
result.decimal_places = self._fix_decimal_places(other)
return result

def __rtruediv__(self, other):
# Backported from py-moneyd, non released bug-fix
# https://github.com/py-moneyed/py-moneyed/blob/c518745dd9d7902781409daec1a05699799474dd/moneyed/classes.py#L217-L218
raise TypeError("Cannot divide non-Money by a Money instance.")

@property
def is_localized(self):
if self.use_l10n is None:
Expand Down Expand Up @@ -89,7 +94,6 @@ def __round__(self, n=None):
__radd__ = __add__
__rsub__ = __sub__
__rmul__ = __mul__
__rtruediv__ = __truediv__


def get_current_locale():
Expand Down
5 changes: 5 additions & 0 deletions tests/test_money.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def test_default_truediv():
assert Money(10, "USD") / 2 == Money(5, "USD")


def test_reverse_truediv_fails():
with pytest.raises(TypeError):
10 / Money(5, "USD")


@pytest.mark.parametrize("locale, expected", (("pl", "PL_PL"), ("pl_PL", "pl_PL")))
def test_get_current_locale(locale, expected):
with override(locale):
Expand Down

0 comments on commit 2b3d0a4

Please sign in to comment.