mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 08:56:34 +03:00
Range objects cannot be ordered
This commit is contained in:
parent
25ef540aa3
commit
841ddaba87
|
@ -147,6 +147,11 @@ class Range(object):
|
|||
def __hash__(self):
|
||||
return hash((self._lower, self._upper, self._bounds))
|
||||
|
||||
def __lt__(self, other):
|
||||
raise TypeError('Range objects are not ordered')
|
||||
|
||||
__le__ = __gt__ = __ge__ = __lt__
|
||||
|
||||
|
||||
def register_range(pgrange, pyrange, conn_or_curs, globally=False):
|
||||
"""Register a typecaster and an adapter for range a range type.
|
||||
|
|
|
@ -915,6 +915,13 @@ class RangeTestCase(unittest.TestCase):
|
|||
assert_not_equal(Range(10, 20), Range(11, 20))
|
||||
assert_not_equal(Range(10, 20, '[)'), Range(10, 20, '[]'))
|
||||
|
||||
def test_not_ordered(self):
|
||||
from psycopg2.extras import Range
|
||||
self.assertRaises(TypeError, lambda: Range(empty=True) < Range(0,4))
|
||||
self.assertRaises(TypeError, lambda: Range(1,2) > Range(0,4))
|
||||
self.assertRaises(TypeError, lambda: Range(1,2) <= Range())
|
||||
self.assertRaises(TypeError, lambda: Range(1,2) >= Range())
|
||||
|
||||
|
||||
def skip_if_no_range(f):
|
||||
def skip_if_no_range_(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user