raising an exception here rather than returning False causes problems with SQLAlchemy's internal state tracking

This commit is contained in:
Chris Withers 2013-05-26 21:58:39 +01:00
parent 8bb44f3444
commit b6a9e0ffaf
2 changed files with 2 additions and 8 deletions

View File

@ -122,7 +122,7 @@ class Range(object):
def __eq__(self, other): def __eq__(self, other):
if not isinstance(other, self.__class__): if not isinstance(other, self.__class__):
raise TypeError('Cannot compare %r with %r' % (self, other)) return False
return (self._lower == other._lower return (self._lower == other._lower
and self._upper == other._upper and self._upper == other._upper
and self._bounds == other._bounds) and self._bounds == other._bounds)

View File

@ -1214,13 +1214,7 @@ class RangeTestCase(unittest.TestCase):
def test_eq_wrong_type(self): def test_eq_wrong_type(self):
from psycopg2.extras import Range from psycopg2.extras import Range
try: self.assertFalse(Range(10, 20)==())
Range(10, 20)==()
except TypeError, e:
self.assertEqual(
str(e), "Cannot compare Range(10, 20, '[)') with ()")
else:
self.fail('No exception raised')
def test_not_ordered(self): def test_not_ordered(self):
from psycopg2.extras import Range from psycopg2.extras import Range