29
29
from azul import (
30
30
R ,
31
31
config ,
32
- reject ,
33
32
)
34
33
from azul .attrs import (
35
34
SerializableAttrs ,
@@ -185,8 +184,8 @@ def __attrs_post_init__(self):
185
184
# partition_prefix is a valid UUID prefix, we restrict the number of
186
185
# characters from the concatenation to be within the first
187
186
# dash-seperated group.
188
- reject ( len (self .common ) + self .partition > 8 ,
189
- 'Invalid common prefix and partition length' , self )
187
+ assert len (self .common ) + self .partition <= 8 , R (
188
+ 'Invalid common prefix and partition length' , self )
190
189
191
190
@classmethod
192
191
def parse (cls , prefix : str ) -> Self :
@@ -202,13 +201,13 @@ def parse(cls, prefix: str) -> Self:
202
201
>>> Prefix.parse('aa/')
203
202
Traceback (most recent call last):
204
203
...
205
- azul.RequirementError: ('Prefix source cannot end in a delimiter', 'aa/', '/')
204
+ AssertionError: R ('Prefix source cannot end in a delimiter', 'aa/', '/')
206
205
207
206
>>> Prefix.parse('8f538f53/1').partition_prefixes() # doctest: +NORMALIZE_WHITESPACE
208
207
Traceback (most recent call last):
209
208
...
210
- azul.RequirementError: ('Invalid common prefix and partition length',
211
- Prefix(common='8f538f53', partition=1))
209
+ AssertionError: R ('Invalid common prefix and partition length',
210
+ Prefix(common='8f538f53', partition=1))
212
211
213
212
>>> list(Prefix.parse('8f538f53/0').partition_prefixes())
214
213
['8f538f53']
@@ -221,12 +220,12 @@ def parse(cls, prefix: str) -> Self:
221
220
>>> Prefix.parse('')
222
221
Traceback (most recent call last):
223
222
...
224
- azul.RequirementError: Cannot parse an empty prefix source
223
+ AssertionError: R(' Cannot parse an empty prefix source')
225
224
"""
226
225
source_delimiter = '/'
227
- reject ( prefix == '' , 'Cannot parse an empty prefix source' )
228
- reject ( prefix .endswith (source_delimiter ),
229
- 'Prefix source cannot end in a delimiter' , prefix , source_delimiter )
226
+ assert prefix != '' , R ( 'Cannot parse an empty prefix source' )
227
+ assert not prefix .endswith (source_delimiter ), R (
228
+ 'Prefix source cannot end in a delimiter' , prefix , source_delimiter )
230
229
partition : str | int
231
230
try :
232
231
entry , partition = prefix .split (source_delimiter )
@@ -378,7 +377,7 @@ def parse(cls, spec: str) -> Self:
378
377
@classmethod
379
378
def _parse (cls , spec : str ) -> tuple [str , Prefix | None ]:
380
379
rest , sep , prefix = spec .rpartition (':' )
381
- reject ( sep == '' , 'Invalid source specification' , spec )
380
+ assert sep != '' , R ( 'Invalid source specification' , spec )
382
381
prefix = Prefix .parse (prefix ) if prefix else None
383
382
return rest , prefix
384
383
@@ -421,7 +420,7 @@ def parse(cls, spec: str) -> 'SimpleSourceSpec':
421
420
>>> SimpleSourceSpec.parse('foo')
422
421
Traceback (most recent call last):
423
422
...
424
- azul.RequirementError: ('Invalid source specification', 'foo')
423
+ AssertionError: R ('Invalid source specification', 'foo')
425
424
426
425
>>> SimpleSourceSpec.parse('foo:8F53/0')
427
426
Traceback (most recent call last):
@@ -641,4 +640,4 @@ def __attrs_post_init__(self):
641
640
# Most bits in a v4 or v5 UUID are pseudo-random, including the leading
642
641
# 32 bits but those are followed by a couple of deterministic ones.
643
642
# For simplicity, we'll limit ourselves to 2 ** 32 leaf partitions.
644
- reject ( self .prefix_length > 32 )
643
+ assert self .prefix_length <= 32 , R ( 'Too many partitions' , self . prefix_length )
0 commit comments