Always define __ne__ when __eq__

This commit is contained in:
Ask Solem 2013-06-27 17:10:54 +01:00
parent 597dabfbd8
commit 97a67498d8
3 changed files with 13 additions and 4 deletions

View File

@ -271,7 +271,10 @@ class Exchange(MaybeChannelBound):
self.durable == other.durable and
self.auto_delete == other.auto_delete and
self.delivery_mode == other.delivery_mode)
return False
return NotImplemented
def __ne__(self, other):
return not self.__eq__(other)
def __repr__(self):
return super(Exchange, self).__repr__(str(self))
@ -642,7 +645,10 @@ class Queue(MaybeChannelBound):
self.durable == other.durable and
self.exclusive == other.exclusive and
self.auto_delete == other.auto_delete)
return False
return NotImplemented
def __ne__(self, other):
return not self.__eq__(other)
def __repr__(self):
s = super(Queue, self).__repr__

View File

@ -94,7 +94,7 @@ class test_Exchange(TestCase):
e3 = Exchange('foo', 'topic')
self.assertNotEqual(e1, e3)
self.assertFalse(e1.__eq__(True))
self.assertEqual(e1.__eq__(True), NotImplemented)
def test_revive(self):
exchange = Exchange('foo', 'direct')
@ -264,7 +264,7 @@ class test_Queue(TestCase):
q1 = Queue('xxx', Exchange('xxx', 'direct'), 'xxx')
q2 = Queue('xxx', Exchange('xxx', 'direct'), 'xxx')
self.assertEqual(q1, q2)
self.assertFalse(q1.__eq__(True))
self.assertEqual(q1.__eq__(True), NotImplemented)
q3 = Queue('yyy', Exchange('xxx', 'direct'), 'xxx')
self.assertNotEqual(q1, q3)

View File

@ -38,6 +38,9 @@ class promise(object):
def __eq__(self, rhs):
return self() == rhs
def __ne__(self, rhs):
return self() != rhs
def __deepcopy__(self, memo):
memo[id(self)] = self
return self