vimeo / py-money

Money class for Python 3
MIT License
125 stars 27 forks source link

`__eq__` is too rigid #10

Open avanov opened 5 years ago

avanov commented 5 years ago

Hi!

The current implementation of __eq__ for Money is too rigid and cannot be used for inclusion tests:

>>> from money.currency import Currency
>>> from money.money import Money
>>> x = Money('10.00', Currency.USD)
>>> x in (None, Money('10.00', Currency.USD))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<...>/lib/python3.7/site-packages/money/money.py", line 80, in __eq__
    raise InvalidOperandError
money.exceptions.InvalidOperandError: Invalid operand types for operation
>>> x in (Money('10.00', Currency.USD), None)
True
nickyr commented 5 years ago

Sorry I haven't had a chance to respond...was on vacation and I've been busy catching up. It does look like this should be fixed. Feel free to open a pull request, if not, I'll try to do one in the near future.

suspectpart commented 3 years ago

I created a PR as I plan to use this library and would like to have the __eq__ behavior fixed. Happy to perform additional changes if that fix is not appropriate yet.