summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Withers <chris@simplistix.co.uk>2013-05-26 22:20:07 +0100
committerChris Withers <chris@simplistix.co.uk>2013-05-26 22:20:07 +0100
commit28276e3eb17eb67178d2fa742a799c693b4d995c (patch)
tree77338f14caa4e11895d69a8bb207f3c6b9510bae
parentb6a9e0ffaf4748d3019b8ab4bbcf9f794e49fc7a (diff)
downloadpsycopg2-28276e3eb17eb67178d2fa742a799c693b4d995c.tar.gz
cater for comparison of subclasses
-rw-r--r--lib/_range.py2
-rwxr-xr-xtests/test_types_extras.py9
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/_range.py b/lib/_range.py
index 16b51a5..0f15990 100644
--- a/lib/_range.py
+++ b/lib/_range.py
@@ -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
diff --git a/tests/test_types_extras.py b/tests/test_types_extras.py
index 5b0c2af..eded26a 100755
--- a/tests/test_types_extras.py
+++ b/tests/test_types_extras.py
@@ -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))