Merge "Prevent instantiation of ShardRangeOuterBound"

This commit is contained in:
Zuul 2021-03-25 21:50:57 +00:00 committed by Gerrit Code Review
commit 805451c00a
2 changed files with 8 additions and 1 deletions

View File

@ -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

View File

@ -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)