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

Make Currencies comparable #16

Open
CGaul opened this issue Oct 28, 2022 · 0 comments
Open

Make Currencies comparable #16

CGaul opened this issue Oct 28, 2022 · 0 comments

Comments

@CGaul
Copy link

CGaul commented Oct 28, 2022

Hi there!
Out of curiosity, was there any decision behind not implementing the __eq__ method inside the Currency class?

In my - maybe naive - understanding, it would make sense to be able to compare Currency objects like so:
Currency('USD') == Currency('USD')
which as of now returns False, as the object's pointers are compared, not the values.

My workaround for this is as follows (python 3.10 code, for python < 3.10 the __ne__ method also needs to be implemented)

class ComparableCurrency(Currency):
    def __eq__(self, other):
        return isinstance(other, Currency) and self.get_money_currency() == other.get_money_currency()

If for any reason, it doesn't make sense to compare two Currencies with each other, or the implementation on currency.get_money_currency() is too simple, I would really like to undestand the problems with that.

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

No branches or pull requests

1 participant