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: I40878c38fd27933d73225ba49bd69b425f13dc6a
This commit is contained in:
parent
6f2112caa8
commit
e6e2ef4d69
cinder
@ -428,6 +428,9 @@ class CinderComparableObject(base.ComparableVersionedObject):
|
||||
return self.obj_to_primitive() == obj.obj_to_primitive()
|
||||
return False
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
|
||||
class ObjectListBase(base.ObjectListBase):
|
||||
def obj_make_compatible(self, primitive, target_version):
|
||||
|
@ -87,6 +87,9 @@ class Comment(object):
|
||||
def __eq__(self, actual):
|
||||
return (dict(ast.literal_eval(actual)) == self.expected)
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
|
||||
class HPE3PARBaseDriver(object):
|
||||
|
||||
|
@ -403,6 +403,9 @@ class NaElement(object):
|
||||
def __eq__(self, other):
|
||||
return str(self) == str(other)
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
def __hash__(self):
|
||||
return hash(str(self))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user