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: Iebabc4deea0aadbec4e73aae52e78bfd84209379
This commit is contained in:
gecong1973 2016-09-05 09:21:00 +08:00
parent 2bf2071a81
commit 2c12970756
1 changed files with 3 additions and 0 deletions

View File

@ -27,3 +27,6 @@ class AuthDetails(object):
self.groups == other.groups and
self.user_id == other.user_id and
self.project_id == other.project_id)
def __ne__(self, other):
return not self.__eq__(other)