From a070f5b16cfac902ffd36477ad8c9c7688c2d2c7 Mon Sep 17 00:00:00 2001 From: gecong1973 Date: Wed, 23 Nov 2016 17:09:15 +0800 Subject: [PATCH] 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 --- cloudkittyclient/apiclient/base.py | 3 +++ cloudkittyclient/apiclient/fake_client.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/cloudkittyclient/apiclient/base.py b/cloudkittyclient/apiclient/base.py index 67e8dec..be4b99e 100644 --- a/cloudkittyclient/apiclient/base.py +++ b/cloudkittyclient/apiclient/base.py @@ -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 diff --git a/cloudkittyclient/apiclient/fake_client.py b/cloudkittyclient/apiclient/fake_client.py index 0634298..c100e2b 100644 --- a/cloudkittyclient/apiclient/fake_client.py +++ b/cloudkittyclient/apiclient/fake_client.py @@ -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):