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
This commit is contained in:
gengchc2 2016-09-05 16:09:59 +08:00 committed by John L. Villalovos
parent b479defac7
commit 41c0413adb

View File

@ -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)