Prevent instantiation of ShardRangeOuterBound
Only the subclasses should be instantiated. Co-Authored-By: Tim Burke <tim.burke@gmail.com> Change-Id: I9b90863bb502ca8b95e626e83775475c352a7a4d Related-Change: I21292e7991e93834b35cda6f5daea4c552a8e999
This commit is contained in:
parent
b17dd7ec75
commit
4bc2b3ef97
|
@ -4972,11 +4972,15 @@ except TypeError:
|
|||
|
||||
class ShardRangeOuterBound(object):
|
||||
"""
|
||||
A custom singleton type used for the outer bounds of ShardRanges.
|
||||
A custom singleton type to be subclassed for the outer bounds of
|
||||
ShardRanges.
|
||||
"""
|
||||
_singleton = None
|
||||
|
||||
def __new__(cls):
|
||||
if cls is ShardRangeOuterBound:
|
||||
raise TypeError('ShardRangeOuterBound is an abstract class; '
|
||||
'only subclasses should be instantiated')
|
||||
if cls._singleton is None:
|
||||
cls._singleton = super(ShardRangeOuterBound, cls).__new__(cls)
|
||||
return cls._singleton
|
||||
|
|
|
@ -7732,6 +7732,9 @@ class TestShardRange(unittest.TestCase):
|
|||
self.ts_iter = make_timestamp_iter()
|
||||
|
||||
def test_min_max_bounds(self):
|
||||
with self.assertRaises(TypeError):
|
||||
utils.ShardRangeOuterBound()
|
||||
|
||||
# max
|
||||
self.assertEqual(utils.ShardRange.MAX, utils.ShardRange.MAX)
|
||||
self.assertFalse(utils.ShardRange.MAX > utils.ShardRange.MAX)
|
||||
|
|
Loading…
Reference in New Issue