From 41c0413adb6076d6c43a0de0b0b9be5d890551ef Mon Sep 17 00:00:00 2001 From: gengchc2 Date: Mon, 5 Sep 2016 16:09:59 +0800 Subject: [PATCH] Add __ne__() function for API Version object In Python 3 the __ne__() function by default delegates to __eq__() and inverts the result[1], but in Python 2 they urge you to define __ne__() when you define __eq__() for it to work properly. 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[2]. [1] https://docs.python.org/3/reference/datamodel.html [2] https://docs.python.org/2/reference/datamodel.html Change-Id: Ic96692ab5d165a66aa5fdbea3d0c8e3a7cc5a821 --- ironic/api/controllers/base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ironic/api/controllers/base.py b/ironic/api/controllers/base.py index f49ef044dc..03aac37767 100644 --- a/ironic/api/controllers/base.py +++ b/ironic/api/controllers/base.py @@ -110,3 +110,6 @@ class Version(object): def __eq__(a, b): return (a.major, a.minor) == (b.major, b.minor) + + def __ne__(self, other): + return not self.__eq__(other)