Add __ne__ built-in function

In Python 3 __ne__ by default delegates to __eq__ and inverts the
result, but in Python 2 they urge you to define __ne__ when you define
__eq__ for it to work properly [1]. 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.

[1]https://docs.python.org/2/reference/datamodel.html#object.__ne__

Change-Id: I6adceadb6e3749e34cf847654f28a3b6eea832fd
This commit is contained in:
howardlee 2016-11-16 16:20:29 +08:00
parent d26d358145
commit 2b3b1792d5

@ -169,6 +169,9 @@ class MyComparator(object):
def __eq__(self, rhs):
return self.equals(rhs)
def __ne__(self, rhs):
return not self.__eq__(rhs)
class CLITestV10Base(testtools.TestCase):