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].
[1]https://docs.python.org/2/reference/datamodel.html#object.__ne__

Change-Id: Ibc8ca97679c1e036290d8e745eae2dbbca4913ad
This commit is contained in:
yuyafei 2016-07-04 16:53:27 +08:00
parent f09148bb51
commit cf0dc61303
2 changed files with 6 additions and 0 deletions

View File

@ -86,6 +86,9 @@ class Host(object):
other, Host.__class__.__name__))
return self.ip == other.ip and self.status == other.status
def __ne__(self, other):
return not self.__eq__(other)
class VMScenario(nova_utils.NovaScenario, cinder_utils.CinderScenario):
"""Base class for VM scenarios with basic atomic actions.

View File

@ -36,6 +36,9 @@ class Variants(object):
def __eq__(self, val):
return getattr(val, "variants", val) == self.variants
def __ne__(self, other):
return not self.__eq__(other)
def __contains__(self, val):
return val in self.variants