Skip to content

Commit 7af4a19

Browse files
committed
Annotate RecordDAWG and IntDAWG
1 parent d05dde1 commit 7af4a19

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

dawg_python/dawgs.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
if TYPE_CHECKING:
1010
from pathlib import Path
11-
from typing import Generator, Mapping
11+
from typing import Any, Generator, Mapping
1212

1313
from typing_extensions import Self, TypeAlias
1414

@@ -417,7 +417,7 @@ def _similar_item_values(
417417

418418
return res
419419

420-
def similar_item_values(self, key, replaces):
420+
def similar_item_values(self, key: str, replaces: CompiledReplaces) -> list[bytes]:
421421
"""
422422
Returns a list of values for all variants of the ``key``
423423
in this DAWG according to ``replaces``.
@@ -431,20 +431,20 @@ def similar_item_values(self, key, replaces):
431431

432432

433433
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:
435435
super().__init__(payload_separator)
436-
self._struct = struct.Struct(str(fmt))
436+
self._struct = struct.Struct(fmt)
437437
self.fmt = fmt
438438

439-
def _value_for_index(self, index):
439+
def _value_for_index(self, index: int) -> list[tuple[Any, ...]]:
440440
value = super()._value_for_index(index)
441441
return [self._struct.unpack(val) for val in value]
442442

443-
def items(self, prefix=""):
443+
def items(self, prefix: str | bytes = "") -> list[tuple[str, tuple[Any, ...]]]:
444444
res = super().items(prefix)
445445
return [(key, self._struct.unpack(val)) for (key, val) in res]
446446

447-
def iteritems(self, prefix=""):
447+
def iteritems(self, prefix: str | bytes = "") -> Generator[tuple[str, tuple[Any, ...]], None, None]:
448448
res = super().iteritems(prefix)
449449
return ((key, self._struct.unpack(val)) for (key, val) in res)
450450

@@ -458,13 +458,13 @@ class IntDAWG(DAWG):
458458
It can store integer values for unicode keys.
459459
"""
460460

461-
def __getitem__(self, key):
461+
def __getitem__(self, key: str | bytes) -> int | None:
462462
res = self.get(key, LOOKUP_ERROR)
463463
if res == LOOKUP_ERROR:
464464
raise KeyError(key)
465465
return res
466466

467-
def get(self, key, default=None):
467+
def get(self, key: str | bytes, default: int | None = None) -> int | None:
468468
"""
469469
Return value for the given key or ``default`` if the key is not found.
470470
"""
@@ -475,7 +475,7 @@ def get(self, key, default=None):
475475
return default
476476
return res
477477

478-
def b_get_value(self, key):
478+
def b_get_value(self, key: bytes) -> int:
479479
return self.dct.find(key)
480480

481481

0 commit comments

Comments
 (0)