@@ -411,14 +411,14 @@ class SearchValue(NamedTuple):
411
411
raw_value : str | float | datetime | Sequence [float ] | Sequence [str ]
412
412
413
413
@property
414
- def value (self ):
414
+ def value (self ) -> Any :
415
415
if _is_wildcard (self .raw_value ):
416
416
return translate_wildcard (self .raw_value )
417
417
elif isinstance (self .raw_value , str ):
418
418
return translate_escape_sequences (self .raw_value )
419
419
return self .raw_value
420
420
421
- def to_query_string (self ):
421
+ def to_query_string (self ) -> str :
422
422
# for any sequence (but not string) we want to iterate over the items
423
423
# we do that because a simple str() would not be usable for strings
424
424
# str(["a","b"]) == "['a', 'b']" but we would like "[a,b]"
@@ -511,7 +511,7 @@ class SearchFilter(NamedTuple):
511
511
operator : str
512
512
value : SearchValue
513
513
514
- def __str__ (self ):
514
+ def __str__ (self ) -> str :
515
515
return f"{ self .key .name } { self .operator } { self .value .raw_value } "
516
516
517
517
def to_query_string (self ) -> str :
@@ -690,14 +690,14 @@ def _get_fallback_builder() -> UnresolvedQuery:
690
690
self .get_function_result_type = _get_fallback_builder ().get_function_result_type
691
691
692
692
@cached_property
693
- def key_mappings_lookup (self ):
694
- lookup = {}
695
- for target_field , source_fields in self . config . key_mappings . items ():
696
- for source_field in source_fields :
697
- lookup [ source_field ] = target_field
698
- return lookup
699
-
700
- def is_numeric_key (self , key ) :
693
+ def key_mappings_lookup (self ) -> dict [ str , str ] :
694
+ return {
695
+ source_field : target_field
696
+ for target_field , source_fields in self . config . key_mappings . items ()
697
+ for source_field in source_fields
698
+ }
699
+
700
+ def is_numeric_key (self , key : str ) -> bool :
701
701
return (
702
702
key in self .config .numeric_keys
703
703
or is_measurement (key )
@@ -707,7 +707,7 @@ def is_numeric_key(self, key):
707
707
or self .is_size_key (key )
708
708
)
709
709
710
- def is_duration_key (self , key ) :
710
+ def is_duration_key (self , key : str ) -> bool :
711
711
duration_types = [* DURATION_UNITS , "duration" ]
712
712
return (
713
713
key in self .config .duration_keys
@@ -716,13 +716,13 @@ def is_duration_key(self, key):
716
716
or self .get_field_type (key ) in duration_types
717
717
)
718
718
719
- def is_size_key (self , key ) :
719
+ def is_size_key (self , key : str ) -> bool :
720
720
return self .get_field_type (key ) in SIZE_UNITS
721
721
722
- def is_date_key (self , key ) :
722
+ def is_date_key (self , key : str ) -> bool :
723
723
return key in self .config .date_keys
724
724
725
- def is_boolean_key (self , key ) :
725
+ def is_boolean_key (self , key : str ) -> bool :
726
726
return key in self .config .boolean_keys
727
727
728
728
def visit_search (self , node , children ):
@@ -731,18 +731,18 @@ def visit_search(self, node, children):
731
731
def visit_term (self , node , children ):
732
732
return remove_optional_nodes (flatten (children [0 ]))
733
733
734
- def visit_boolean_operator (self , node , children ) :
734
+ def visit_boolean_operator (self , node : Node , children : tuple [ QueryOp ]) -> QueryOp :
735
735
if not self .config .allow_boolean :
736
736
raise InvalidSearchQuery (
737
737
'Boolean statements containing "OR" or "AND" are not supported in this search'
738
738
)
739
739
740
740
return children [0 ]
741
741
742
- def visit_free_text_unquoted (self , node , children ) :
742
+ def visit_free_text_unquoted (self , node : Node , children : object ) -> str | None :
743
743
return node .text .strip (" " ) or None
744
744
745
- def visit_free_text (self , node , children ) :
745
+ def visit_free_text (self , node : Node , children : tuple [ str ]) -> SearchFilter | None :
746
746
if not children [0 ]:
747
747
return None
748
748
# Free text searches need to be treated like they were wildcards
@@ -1206,10 +1206,10 @@ def visit_search_key(self, node, children):
1206
1206
return key
1207
1207
return SearchKey (self .key_mappings_lookup .get (key , key ))
1208
1208
1209
- def visit_text_key (self , node , children ) :
1209
+ def visit_text_key (self , node : Node , children : tuple [ SearchKey ]) -> SearchKey :
1210
1210
return children [0 ]
1211
1211
1212
- def visit_value (self , node , children ) :
1212
+ def visit_value (self , node : Node , children : object ) -> str :
1213
1213
# A properly quoted value will match the quoted value regex, so any unescaped
1214
1214
# quotes are errors.
1215
1215
value = node .text
@@ -1236,13 +1236,13 @@ def visit_quoted_value(self, node, children):
1236
1236
1237
1237
return value
1238
1238
1239
- def visit_in_value (self , node , children ) :
1239
+ def visit_in_value (self , node : Node , children : object ) -> str :
1240
1240
return node .text .replace ('\\ "' , '"' )
1241
1241
1242
- def visit_text_in_value (self , node , children ) :
1242
+ def visit_text_in_value (self , node : Node , children : tuple [ str ]) -> str :
1243
1243
return children [0 ]
1244
1244
1245
- def visit_search_value (self , node , children ) :
1245
+ def visit_search_value (self , node : Node , children : tuple [ str ]) -> SearchValue :
1246
1246
return SearchValue (children [0 ])
1247
1247
1248
1248
def visit_numeric_value (self , node , children ):
@@ -1252,7 +1252,7 @@ def visit_numeric_value(self, node, children):
1252
1252
1253
1253
return [f"{ sign } { value } " , suffix ]
1254
1254
1255
- def visit_boolean_value (self , node , children ) :
1255
+ def visit_boolean_value (self , node : Node , children : object ) -> Node :
1256
1256
return node
1257
1257
1258
1258
def visit_text_in_list (self , node , children ):
@@ -1261,58 +1261,60 @@ def visit_text_in_list(self, node, children):
1261
1261
def visit_numeric_in_list (self , node , children ):
1262
1262
return process_list (children [1 ], children [2 ])
1263
1263
1264
- def visit_iso_8601_date_format (self , node , children ) :
1264
+ def visit_iso_8601_date_format (self , node : Node , children : object ) -> str :
1265
1265
return node .text
1266
1266
1267
- def visit_rel_date_format (self , node , children ) :
1267
+ def visit_rel_date_format (self , node : Node , children : object ) -> Node :
1268
1268
return node
1269
1269
1270
- def visit_duration_format (self , node , children ):
1270
+ def visit_duration_format (
1271
+ self , node : Node , children : tuple [str , tuple [Node ], Node ]
1272
+ ) -> list [str ]:
1271
1273
return [children [0 ], children [1 ][0 ].text ]
1272
1274
1273
- def visit_size_format (self , node , children ) :
1275
+ def visit_size_format (self , node : Node , children : tuple [ str , tuple [ Node ]]) -> list [ str ] :
1274
1276
return [children [0 ], children [1 ][0 ].text ]
1275
1277
1276
- def visit_percentage_format (self , node , children ) :
1278
+ def visit_percentage_format (self , node : Node , children : tuple [ str , Node ]) -> str :
1277
1279
return children [0 ]
1278
1280
1279
- def visit_operator (self , node , children ) :
1281
+ def visit_operator (self , node : Node , children : object ) -> str :
1280
1282
return node .text
1281
1283
1282
- def visit_or_operator (self , node , children ) :
1284
+ def visit_or_operator (self , node : Node , children : object ) -> str :
1283
1285
return node .text .upper ()
1284
1286
1285
- def visit_and_operator (self , node , children ) :
1287
+ def visit_and_operator (self , node : Node , children : object ) -> str :
1286
1288
return node .text .upper ()
1287
1289
1288
- def visit_numeric (self , node , children ) :
1290
+ def visit_numeric (self , node : Node , children : object ) -> str :
1289
1291
return node .text
1290
1292
1291
- def visit_open_paren (self , node , children ) :
1293
+ def visit_open_paren (self , node : Node , children : object ) -> str :
1292
1294
return node .text
1293
1295
1294
- def visit_closed_paren (self , node , children ) :
1296
+ def visit_closed_paren (self , node : Node , children : object ) -> str :
1295
1297
return node .text
1296
1298
1297
- def visit_open_bracket (self , node , children ) :
1299
+ def visit_open_bracket (self , node : Node , children : object ) -> str :
1298
1300
return node .text
1299
1301
1300
- def visit_closed_bracket (self , node , children ) :
1302
+ def visit_closed_bracket (self , node : Node , children : object ) -> str :
1301
1303
return node .text
1302
1304
1303
- def visit_sep (self , node , children ) :
1305
+ def visit_sep (self , node : Node , children : object ) -> Node :
1304
1306
return node
1305
1307
1306
- def visit_negation (self , node , children ) :
1308
+ def visit_negation (self , node : Node , children : object ) -> Node :
1307
1309
return node
1308
1310
1309
- def visit_comma (self , node , children ) :
1311
+ def visit_comma (self , node : Node , children : object ) -> Node :
1310
1312
return node
1311
1313
1312
- def visit_spaces (self , node , children ) :
1314
+ def visit_spaces (self , node : Node , children : object ) -> str :
1313
1315
return " "
1314
1316
1315
- def generic_visit (self , node , children ) :
1317
+ def generic_visit (self , node : Node , children : Sequence [ Any ]) -> Any :
1316
1318
return children or node
1317
1319
1318
1320
@@ -1358,7 +1360,7 @@ def parse_search_query(
1358
1360
query : str ,
1359
1361
* ,
1360
1362
config : SearchConfig [Literal [False ]],
1361
- params = None ,
1363
+ params : ParamsType | None = None ,
1362
1364
get_field_type : Callable [[str ], str | None ] | None = None ,
1363
1365
get_function_result_type : Callable [[str ], str | None ] | None = None ,
1364
1366
) -> Sequence [SearchFilter | AggregateFilter ]: ...
@@ -1369,7 +1371,7 @@ def parse_search_query(
1369
1371
query : str ,
1370
1372
* ,
1371
1373
config : SearchConfig [Literal [True ]] | None = None ,
1372
- params = None ,
1374
+ params : ParamsType | None = None ,
1373
1375
get_field_type : Callable [[str ], str | None ] | None = None ,
1374
1376
get_function_result_type : Callable [[str ], str | None ] | None = None ,
1375
1377
) -> Sequence [QueryToken ]: ...
@@ -1379,7 +1381,7 @@ def parse_search_query(
1379
1381
query : str ,
1380
1382
* ,
1381
1383
config : SearchConfig [Any ] | None = None ,
1382
- params = None ,
1384
+ params : ParamsType | None = None ,
1383
1385
get_field_type : Callable [[str ], str | None ] | None = None ,
1384
1386
get_function_result_type : Callable [[str ], str | None ] | None = None ,
1385
1387
) -> Sequence [QueryToken ]:
0 commit comments