diff options
author | Raymond Hettinger <python@rcn.com> | 2004-07-05 22:53:03 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-07-05 22:53:03 (GMT) |
commit | 0aeac107cadd1472e5ea109f7f29e6a6527ae1ec (patch) | |
tree | 4d0d33fdc1199cdc32794cdfcc20b2f90a44f4b9 /Lib/decimal.py | |
parent | 10959b1c2acb48ebcdc909421354543043cfd671 (diff) | |
download | cpython-0aeac107cadd1472e5ea109f7f29e6a6527ae1ec.zip cpython-0aeac107cadd1472e5ea109f7f29e6a6527ae1ec.tar.gz cpython-0aeac107cadd1472e5ea109f7f29e6a6527ae1ec.tar.bz2 |
* Add __eq__ and __ne__ so that things like list.index() work properly
for lists of mixed types.
* Test that sort works.
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r-- | Lib/decimal.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py index 500ba07..1d13767 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -8,10 +8,6 @@ # and Tim Peters -# Todo: -# Add rich comparisons for equality testing with other types - - """ This is a Py2.3 implementation of decimal floating point arithmetic based on the General Decimal Arithmetic Specification: @@ -644,6 +640,16 @@ class Decimal(object): return -1 return 1 + def __eq__(self, other): + if not isinstance(other, (Decimal, int, long)): + return False + return self.__cmp__(other) == 0 + + def __ne__(self, other): + if not isinstance(other, (Decimal, int, long)): + return True + return self.__cmp__(other) != 0 + def compare(self, other, context=None): """Compares one to another. |