Message255339
The documentation for functools.total_ordering states that rich comparison can be enabled on a class by specifying an __eq__ method, and one of __lt__(), __le__(), __gt__(), or __ge__(). If these instructions are followed, this results in an incorrect evaluation of the not equal operator:
Here's an example:
from functools import total_ordering
@total_ordering
class Value(object):
def __init__(self, value):
self.value = value
def __eq__(self, other):
return self.value == other.value
def __lt__(self, other):
return self.value < other.value
>>> a = Value(3)
>>> b = Value(3)
>>> a == b
True
>>> a != b
True
I've tested this on 2.7.10.
Either the documentation or the behaviour should be corrected.
https://docs.python.org/2/library/functools.html#functools.total_ordering |
|
Date |
User |
Action |
Args |
2015-11-25 13:12:49 | David Seddon | set | recipients:
+ David Seddon |
2015-11-25 13:12:49 | David Seddon | set | messageid: <1448457169.16.0.121144285875.issue25732@psf.upfronthosting.co.za> |
2015-11-25 13:12:49 | David Seddon | link | issue25732 messages |
2015-11-25 13:12:48 | David Seddon | create | |
|