From 797d376c6907025dea5df2d477fa959c40e23409 Mon Sep 17 00:00:00 2001 From: gecong1973 Date: Mon, 17 Oct 2016 08:51:06 +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: I733f87fa5f9f69eac6f4e1eb930a9f299c0052e4 --- oslo_utils/tests/test_reflection.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/oslo_utils/tests/test_reflection.py b/oslo_utils/tests/test_reflection.py index cca92b8a..34384f79 100644 --- a/oslo_utils/tests/test_reflection.py +++ b/oslo_utils/tests/test_reflection.py @@ -146,6 +146,9 @@ class CallbackEqualityTest(test_base.BaseTestCase): def __eq__(self, other): return True + def __ne__(self, other): + return not self.__eq__(other) + b = A() c = A()