8
8
9
9
if TYPE_CHECKING :
10
10
from pathlib import Path
11
- from typing import Generator , Mapping
11
+ from typing import Any , Generator , Mapping
12
12
13
13
from typing_extensions import Self , TypeAlias
14
14
@@ -417,7 +417,7 @@ def _similar_item_values(
417
417
418
418
return res
419
419
420
- def similar_item_values (self , key , replaces ) :
420
+ def similar_item_values (self , key : str , replaces : CompiledReplaces ) -> list [ bytes ] :
421
421
"""
422
422
Returns a list of values for all variants of the ``key``
423
423
in this DAWG according to ``replaces``.
@@ -431,20 +431,20 @@ def similar_item_values(self, key, replaces):
431
431
432
432
433
433
class RecordDAWG (BytesDAWG ):
434
- def __init__ (self , fmt , payload_separator = PAYLOAD_SEPARATOR ) -> None :
434
+ def __init__ (self , fmt : str | bytes , payload_separator : bytes = PAYLOAD_SEPARATOR ) -> None :
435
435
super ().__init__ (payload_separator )
436
- self ._struct = struct .Struct (str ( fmt ) )
436
+ self ._struct = struct .Struct (fmt )
437
437
self .fmt = fmt
438
438
439
- def _value_for_index (self , index ) :
439
+ def _value_for_index (self , index : int ) -> list [ tuple [ Any , ...]] :
440
440
value = super ()._value_for_index (index )
441
441
return [self ._struct .unpack (val ) for val in value ]
442
442
443
- def items (self , prefix = "" ):
443
+ def items (self , prefix : str | bytes = "" ) -> list [ tuple [ str , tuple [ Any , ...]]] :
444
444
res = super ().items (prefix )
445
445
return [(key , self ._struct .unpack (val )) for (key , val ) in res ]
446
446
447
- def iteritems (self , prefix = "" ):
447
+ def iteritems (self , prefix : str | bytes = "" ) -> Generator [ tuple [ str , tuple [ Any , ...]], None , None ] :
448
448
res = super ().iteritems (prefix )
449
449
return ((key , self ._struct .unpack (val )) for (key , val ) in res )
450
450
@@ -458,13 +458,13 @@ class IntDAWG(DAWG):
458
458
It can store integer values for unicode keys.
459
459
"""
460
460
461
- def __getitem__ (self , key ) :
461
+ def __getitem__ (self , key : str | bytes ) -> int | None :
462
462
res = self .get (key , LOOKUP_ERROR )
463
463
if res == LOOKUP_ERROR :
464
464
raise KeyError (key )
465
465
return res
466
466
467
- def get (self , key , default = None ):
467
+ def get (self , key : str | bytes , default : int | None = None ) -> int | None :
468
468
"""
469
469
Return value for the given key or ``default`` if the key is not found.
470
470
"""
@@ -475,7 +475,7 @@ def get(self, key, default=None):
475
475
return default
476
476
return res
477
477
478
- def b_get_value (self , key ) :
478
+ def b_get_value (self , key : bytes ) -> int :
479
479
return self .dct .find (key )
480
480
481
481
0 commit comments