This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients georg.brandl, terry.reedy
Date 2008-11-23.18:21:31
SpamBayes Score 4.810943e-06
Marked as misclassified No
Message-id <1227464493.77.0.130820783094.issue4395@psf.upfronthosting.co.za>
In-reply-to
Content
3.0c3 doc (Basic customization) says
"There are no implied relationships among the comparison operators. The
truth of x==y does not imply that x!=y is false. Accordingly, when
defining __eq__(), one should also define __ne__() so that the operators
will behave as expected. "

In http://mail.python.org/pipermail/python-ideas/2008-October/002235.html
Guido says
"I should also note that part of George's proposal has already been
implemented: if you define __eq__, you get a complementary __ne__ for
free. However it doesn't work the other way around (defining __ne__
doesn't give you __eq__ for free), and there is no similar
relationship for the ordering operators."

And indeed, as Arnaud Delobelle posted on python-list
class A:
    def __init__(self, x):
        self.x = x
    def __eq__(self, other):
        return self.x == other.x

a, b, c = A(1), A(1), A(2)
print(a==b, b==c, c==a) # True, False, False
print(a!=b, b!=c, c!=a) # False, True, True

Suggested revision:
"There is one implied relationship among comparison operators: defining
__eq__ gives an automatic __ne__ (but not the other way).  There is no
similar relationship for the order comparisons.
History
Date User Action Args
2008-11-23 18:21:34terry.reedysetrecipients: + terry.reedy, georg.brandl
2008-11-23 18:21:33terry.reedysetmessageid: <1227464493.77.0.130820783094.issue4395@psf.upfronthosting.co.za>
2008-11-23 18:21:32terry.reedylinkissue4395 messages
2008-11-23 18:21:31terry.reedycreate