Alir3z4 / Alir3z4/python-currencies

Make Currencies comparable

Offen
#16 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
73
Forks
13
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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)
```python
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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.