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: Id2d32eedddbbbb91c6da6e36f12515972aa9e5a5
This commit is contained in:
gecong1973 2016-11-23 17:09:15 +08:00
parent a93f8b04b1
commit a070f5b16c
2 changed files with 6 additions and 0 deletions

View File

@ -522,6 +522,9 @@ class Resource(object):
return self.id == other.id
return self._info == other._info
def __ne__(self, other):
return not self.__eq__(other)
def is_loaded(self):
return self._loaded

View File

@ -87,6 +87,9 @@ class TestResponse(requests.Response):
self.headers == other.headers and
self._content == other._content)
def __ne__(self, other):
return not self.__eq__(other)
class FakeHTTPClient(client.HTTPClient):