From 97a67498d86d5f84fff8706a4525b960b6945853 Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Thu, 27 Jun 2013 17:10:54 +0100 Subject: [PATCH] Always define __ne__ when __eq__ --- kombu/entity.py | 10 ++++++++-- kombu/tests/test_entities.py | 4 ++-- kombu/utils/functional.py | 3 +++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/kombu/entity.py b/kombu/entity.py index e1d62b43..189c9de3 100644 --- a/kombu/entity.py +++ b/kombu/entity.py @@ -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__ diff --git a/kombu/tests/test_entities.py b/kombu/tests/test_entities.py index 21dcb35d..3fbb5b89 100644 --- a/kombu/tests/test_entities.py +++ b/kombu/tests/test_entities.py @@ -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) diff --git a/kombu/utils/functional.py b/kombu/utils/functional.py index 49a7c6d2..374bf356 100644 --- a/kombu/utils/functional.py +++ b/kombu/utils/functional.py @@ -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