cater for comparison of subclasses

This commit is contained in:
Chris Withers 2013-05-26 22:20:07 +01:00
parent b6a9e0ffaf
commit 28276e3eb1
2 changed files with 10 additions and 1 deletions

View File

@ -121,7 +121,7 @@ class Range(object):
return self._bounds is not None
def __eq__(self, other):
if not isinstance(other, self.__class__):
if not isinstance(other, Range):
return False
return (self._lower == other._lower
and self._upper == other._upper

View File

@ -1216,6 +1216,15 @@ class RangeTestCase(unittest.TestCase):
from psycopg2.extras import Range
self.assertFalse(Range(10, 20)==())
def test_eq_subclass(self):
from psycopg2.extras import Range, NumericRange
class IntRange(NumericRange): pass
class PositiveIntRange(IntRange): pass
self.assertTrue(Range(10, 20)==IntRange(10, 20))
self.assertTrue(PositiveIntRange(10, 20)==IntRange(10, 20))
def test_not_ordered(self):
from psycopg2.extras import Range
self.assertRaises(TypeError, lambda: Range(empty=True) < Range(0,4))