Skip to content

Commit ece96a0

Browse files
committed
Some minor improvements
1 parent a004529 commit ece96a0

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

dawg_python/dawgs.py

+9-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 Any, Generator, Mapping
11+
from typing import Any, Iterator, Mapping
1212

1313
from typing_extensions import Self, TypeAlias
1414

@@ -87,8 +87,8 @@ def similar_keys(self, key: str, replaces: CompiledReplaces) -> list[str]:
8787
"""
8888
return self._similar_keys("", key, self.dct.ROOT, replaces)
8989

90-
@classmethod
91-
def compile_replaces(cls, replaces: Replaces) -> CompiledReplaces:
90+
@staticmethod
91+
def compile_replaces(replaces: Replaces) -> CompiledReplaces:
9292
for k, v in replaces.items():
9393
if len(k) != 1:
9494
msg = "Keys must be single-char unicode strings."
@@ -130,7 +130,6 @@ class CompletionDAWG(DAWG):
130130
DAWG with key completion support.
131131
"""
132132

133-
dct: wrapper.Dictionary
134133
guide: wrapper.Guide | None
135134

136135
def __init__(self) -> None:
@@ -140,7 +139,7 @@ def __init__(self) -> None:
140139
def keys(self, prefix: str = "") -> list[str]:
141140
return list(self.iterkeys(prefix))
142141

143-
def iterkeys(self, prefix: str = "") -> Generator[str, None, None]:
142+
def iterkeys(self, prefix: str = "") -> Iterator[str]:
144143
b_prefix = prefix.encode("utf8")
145144
index = self.dct.follow_bytes(b_prefix, self.dct.ROOT)
146145
if index is None:
@@ -179,7 +178,7 @@ class BytesDAWG(CompletionDAWG):
179178
{unicode -> list of bytes objects} mapping.
180179
"""
181180

182-
def __init__(self, payload_separator: bytes | None = PAYLOAD_SEPARATOR) -> None:
181+
def __init__(self, payload_separator: bytes = PAYLOAD_SEPARATOR) -> None:
183182
super().__init__()
184183
self._payload_separator = payload_separator
185184

@@ -236,7 +235,7 @@ def b_get_value(self, b_key: bytes) -> list[bytes]:
236235
def keys(self, prefix: str | bytes = "") -> list[str]:
237236
return list(self.iterkeys(prefix))
238237

239-
def iterkeys(self, prefix: str | bytes = "") -> Generator[bytes, None, None]:
238+
def iterkeys(self, prefix: str | bytes = "") -> Iterator[bytes]:
240239
if not isinstance(prefix, bytes):
241240
prefix = prefix.encode("utf8")
242241

@@ -258,7 +257,7 @@ def iterkeys(self, prefix: str | bytes = "") -> Generator[bytes, None, None]:
258257
def items(self, prefix: str | bytes = "") -> list[tuple[str, bytes]]:
259258
return list(self.iteritems(prefix))
260259

261-
def iteritems(self, prefix: str | bytes = "") -> Generator[tuple[str, bytes], None, None]:
260+
def iteritems(self, prefix: str | bytes = "") -> Iterator[tuple[str, bytes]]:
262261
if not isinstance(prefix, bytes):
263262
prefix = prefix.encode("utf8")
264263

@@ -394,7 +393,7 @@ def _value_for_index(self, index: int) -> list[tuple[Any, ...]]:
394393
def items(self, prefix: str | bytes = "") -> list[tuple[str, tuple[Any, ...]]]:
395394
return list(self.iteritems(prefix))
396395

397-
def iteritems(self, prefix: str | bytes = "") -> Generator[tuple[str, tuple[Any, ...]], None, None]:
396+
def iteritems(self, prefix: str | bytes = "") -> Iterator[tuple[str, tuple[Any, ...]]]:
398397
res = super().iteritems(prefix)
399398
return ((key, self._struct.unpack(val)) for (key, val) in res)
400399

@@ -438,7 +437,7 @@ class IntCompletionDAWG(CompletionDAWG, IntDAWG):
438437
def items(self, prefix: str | bytes = "") -> list[tuple[str, int]]:
439438
return list(self.iteritems(prefix))
440439

441-
def iteritems(self, prefix: str | bytes = "") -> Generator[tuple[str, int], None, None]:
440+
def iteritems(self, prefix: str | bytes = "") -> Iterator[tuple[str, int]]:
442441
if not isinstance(prefix, bytes):
443442
prefix = prefix.encode("utf8")
444443
index = self.dct.ROOT

0 commit comments

Comments
 (0)