From b6a9e0ffaf4748d3019b8ab4bbcf9f794e49fc7a Mon Sep 17 00:00:00 2001 From: Chris Withers Date: Sun, 26 May 2013 21:58:39 +0100 Subject: [PATCH] raising an exception here rather than returning False causes problems with SQLAlchemy's internal state tracking --- lib/_range.py | 2 +- tests/test_types_extras.py | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/_range.py b/lib/_range.py index 5803a8ab..16b51a5f 100644 --- a/lib/_range.py +++ b/lib/_range.py @@ -122,7 +122,7 @@ class Range(object): def __eq__(self, other): if not isinstance(other, self.__class__): - raise TypeError('Cannot compare %r with %r' % (self, other)) + return False return (self._lower == other._lower and self._upper == other._upper and self._bounds == other._bounds) diff --git a/tests/test_types_extras.py b/tests/test_types_extras.py index 48074d7b..5b0c2af3 100755 --- a/tests/test_types_extras.py +++ b/tests/test_types_extras.py @@ -1214,13 +1214,7 @@ class RangeTestCase(unittest.TestCase): def test_eq_wrong_type(self): from psycopg2.extras import Range - try: - Range(10, 20)==() - except TypeError, e: - self.assertEqual( - str(e), "Cannot compare Range(10, 20, '[)') with ()") - else: - self.fail('No exception raised') + self.assertFalse(Range(10, 20)==()) def test_not_ordered(self): from psycopg2.extras import Range