Skip to content

Commit 670972c

Browse files
committed
Add missing annotations
1 parent d550118 commit 670972c

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

dawg_python/dawgs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DAWG:
2626
def __init__(self) -> None:
2727
self.dct = None
2828

29-
def __contains__(self, key) -> bool:
29+
def __contains__(self, key: str | bytes) -> bool:
3030
if not isinstance(key, bytes):
3131
key = key.encode("utf8")
3232
return self.dct.contains(key)
@@ -73,7 +73,7 @@ def _similar_keys(self, current_prefix: str, key: str, index: int, replace_chars
7373

7474
return res
7575

76-
def similar_keys(self, key: str, replaces: CompiledReplaces):
76+
def similar_keys(self, key: str, replaces: CompiledReplaces) -> list[str]:
7777
"""
7878
Returns all variants of ``key`` in this DAWG according to
7979
``replaces``.
@@ -202,7 +202,7 @@ def __contains__(self, key: str | bytes) -> bool:
202202
key = key.encode("utf8")
203203
return bool(self._follow_key(key))
204204

205-
def __getitem__(self, key):
205+
def __getitem__(self, key: str | bytes) -> list[bytes]:
206206
res = self.get(key)
207207
if res is None:
208208
raise KeyError(key)
@@ -241,7 +241,7 @@ def _value_for_index(self, index: int) -> list[bytes]:
241241

242242
return res
243243

244-
def b_get_value(self, b_key) -> list[bytes]:
244+
def b_get_value(self, b_key: bytes) -> list[bytes]:
245245
index = self._follow_key(b_key)
246246
if not index:
247247
return []

dawg_python/units.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
EXTENSION_BIT = 1 << 9
1111

1212

13-
def has_leaf(base: int, _mask=HAS_LEAF_BIT) -> bool:
13+
def has_leaf(base: int, _mask: int = HAS_LEAF_BIT) -> bool:
1414
"""Check if a unit has a leaf as a child or not."""
1515
return bool(base & _mask)
1616

1717

18-
def value(base: int, _mask=~IS_LEAF_BIT & PRECISION_MASK) -> int:
18+
def value(base: int, _mask: int = ~IS_LEAF_BIT & PRECISION_MASK) -> int:
1919
"""Check if a unit corresponds to a leaf or not."""
2020
return base & _mask
2121

2222

23-
def label(base: int, _mask=IS_LEAF_BIT | 0xFF) -> int:
23+
def label(base: int, _mask: int = IS_LEAF_BIT | 0xFF) -> int:
2424
"""Read a label with a leaf flag from a non-leaf unit."""
2525
return base & _mask
2626

dawg_python/wrapper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
if TYPE_CHECKING:
1010
from io import BytesIO
11+
from pathlib import Path
1112

1213
from typing_extensions import Self
1314

@@ -74,7 +75,7 @@ def follow_bytes(self, s: bytes, index: int) -> int | None:
7475
return index
7576

7677
@classmethod
77-
def load(cls, path) -> Self:
78+
def load(cls, path: str | Path) -> Self:
7879
dawg = cls()
7980
with open(path, "rb") as f:
8081
dawg.read(f)

pyproject.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,17 @@ target-version = "py38"
4242
[tool.ruff.lint]
4343
select = ["ALL"]
4444
ignore = [
45-
"ANN001",
46-
"ANN002",
47-
"ANN201",
48-
"ANN202",
49-
"ANN204",
50-
"ANN206",
51-
# ^^^ Silence warnings about the type annotations for now
52-
5345
"D",
5446
"PTH123",
5547
]
5648
fixable = ["ALL"]
5749

5850
[tool.ruff.lint.per-file-ignores]
5951
"_prepare_dev_data.py" = [
52+
"ANN001",
53+
"ANN002",
54+
"ANN201",
55+
"ANN202",
6056
"ERA001",
6157
]
6258

@@ -65,6 +61,10 @@ fixable = ["ALL"]
6561
]
6662

6763
"bench/*" = [
64+
"ANN001",
65+
"ANN002",
66+
"ANN201",
67+
"ANN202",
6868
"ERA001",
6969
"PERF401",
7070
"PLR0913",
@@ -83,4 +83,4 @@ fixable = ["ALL"]
8383
"S101",
8484
"S301",
8585
"S324",
86-
]
86+
]

0 commit comments

Comments
 (0)