@@ -13,29 +13,30 @@ def __init__(self):
1313 def register_filter (self , key : str , builder : CommonFilterImpl ,
1414 field_extractor_fn : Callable [[str ], AnySqlAlchemyColumn ] = None ):
1515 if key is None or not key :
16- raise ValueError (f "Invalid type key!" )
16+ raise ValueError ("Invalid type key!" )
1717 if key in self ._filters :
1818 raise ValueError (f"filter name already in use with { self ._filters [key ][0 ].__name__ } !" )
1919 self ._filters [key ] = (builder , field_extractor_fn )
2020
2121 def is_mapper_semantic_valid (self , mapper_val ):
2222 if type (mapper_val ) is not tuple :
23- raise ValueError (f "Invalid filter mapper semantic! Expected tuple!" )
23+ raise ValueError ("Invalid filter mapper semantic! Expected tuple!" )
2424 if len (mapper_val ) < 2 or len (mapper_val ) > 3 :
2525 raise ValueError (f"Invalid filter mapper semantic { mapper_val } ! min tuple length should be 2." )
2626 if type (mapper_val [0 ]) is not str :
27- ValueError (f"Invalid filter mapper semantic { mapper_val } ! first tuple element should be field (str)" )
27+ raise ValueError (f"Invalid filter mapper semantic { mapper_val } ! first tuple element should be field (str)" )
2828 if not inspect .isclass (mapper_val [1 ]):
29- raise ValueError (f"Invalid filter mapper semantic { mapper_val [1 ]} ! Expects a class!" )
30- if not issubclass (mapper_val [1 ], CommonFilterImpl ):
31- raise ValueError (f"Invalid filter mapper semantic { mapper_val [1 ]} !"
29+ raise ValueError (f"Invalid filter mapper semantic { mapper_val [1 ]!r } ! Expects a class!" )
30+ if not issubclass (mapper_val [1 ], CommonFilterImpl ) and mapper_val [ 1 ] != CommonFilterImpl :
31+ raise ValueError (f"Invalid filter mapper semantic { mapper_val [1 ]!r } !"
3232 f" Expects a subclass of CommonFilterImpl" )
3333 if len (mapper_val ) == 3 and not isinstance (mapper_val [2 ], types .FunctionType ):
34- raise ValueError (f"positional arg error, expects a callable but received: { mapper_val [2 ]} !" )
34+ raise ValueError (f"positional arg error, expects a callable but received: { mapper_val [2 ]!r } !" )
3535 return True
3636
37- def register_filter_mapper (self , filter_mapper : Dict [str , Tuple [str , CommonFilterImpl ,
38- Optional [Callable [[str ], AnySqlAlchemyColumn ]]]]):
37+ def register_filter_mapper (
38+ self , filter_mapper : Dict [str , Tuple [str , CommonFilterImpl , Optional [Callable [[str ], AnySqlAlchemyColumn ]]]]
39+ ):
3940 for key , val in filter_mapper .items ():
4041 if self .is_mapper_semantic_valid (val ):
4142 self .register_filter (val [0 ], * val [1 :])
@@ -44,7 +45,7 @@ def create(self, key: str, **kwargs):
4445 try :
4546 filter_ , field_extractor_fn = self ._filters [key ]
4647 except KeyError :
47- raise ValueError (f"filter factory couldn't find registered key: { key } " )
48+ raise ValueError (f"filter factory couldn't find registered key { key !r } " )
4849 return filter_ (** kwargs , field_extract_fn = field_extractor_fn )
4950
5051
0 commit comments