diff options
author | yuyafei <yu.yafei@zte.com.cn> | 2016-07-05 14:57:55 +0800 |
---|---|---|
committer | yuyafei <yu.yafei@zte.com.cn> | 2016-07-05 14:58:42 +0800 |
commit | f4f2e6c261b62698eb31e2fc78a2777e54b72594 (patch) | |
tree | 9d3038c88312b25a40bf65b4386e4add427313ec | |
parent | 07c960d46fe8412d98799b1820d57810a9a8a3e7 (diff) | |
download | python-swiftclient-f4f2e6c261b62698eb31e2fc78a2777e54b72594.tar.gz |
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: I5485022f010cdcb88c0d4ebe5c44a39a1bf242b0
-rw-r--r-- | tests/unit/utils.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/tests/unit/utils.py b/tests/unit/utils.py index d04583f..c05146e 100644 --- a/tests/unit/utils.py +++ b/tests/unit/utils.py @@ -494,6 +494,9 @@ class CaptureOutput(object): def __eq__(self, other): return self.out == other + def __ne__(self, other): + return not self.__eq__(other) + def __getattr__(self, name): return getattr(self.out, name) |