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: I3ae84db585355fef864a8beea4ad388ed09e6ff7
This commit is contained in:
yuyafei 2016-07-05 11:11:40 +08:00 committed by yuyafei
parent 0272577c9e
commit 456fe5fca6
3 changed files with 9 additions and 0 deletions

View File

@ -697,6 +697,9 @@ class Stack(collections.Mapping):
"""
return self is other
def __ne__(self, other):
return not self.__eq__(other)
def __str__(self):
"""Return a human-readable string representation of the stack."""
text = 'Stack "%s" [%s]' % (self.name, self.id)

View File

@ -205,6 +205,9 @@ class Stack(
self.refresh() # to make test object comparison work well
return super(Stack, self).__eq__(another)
def __ne__(self, other):
return not self.__eq__(other)
def refresh(self):
db_stack = db_api.stack_get(
self._context, self.id, show_deleted=True)

View File

@ -840,6 +840,9 @@ class WithTemplateTest(StackResourceBaseTest):
self.match = other
return True
def __ne__(self, other):
return not self.__eq__(other)
def test_create_with_template(self):
child_env = {'parameter_defaults': {},
'event_sinks': [],