New submission from Terry J. Reedy <[EMAIL PROTECTED]>: 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. ---------- assignee: georg.brandl components: Documentation messages: 76270 nosy: georg.brandl, tjreedy severity: normal status: open title: Document auto __ne__ generation versions: Python 3.0 _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue4395> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com