Skip to content

Commit db8b3ef

Browse files
Fix all mypy errors and make mypy a CI gate
- bindb.py: stop reusing 'm' for both List[BIN_Tuple] and the Optional[BIN_Tuple] result of StaticPhrases.lookup() - reynir.py: annotate _Sentence._tree (and the local in parse()) as Optional[Node] instead of letting mypy infer type None - Add types-cffi to the dev dependency group so eparser_build.py type-checks - Run mypy in CI on all non-PyPy jobs now that it is clean Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent ed3c792 commit db8b3ef

5 files changed

Lines changed: 34 additions & 6 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ jobs:
3232
run: uv sync --locked
3333
- name: Lint with ruff
3434
run: uv run ruff check src/reynir
35+
- name: Type check with mypy
36+
# mypy is not installed on PyPy (see [dependency-groups] in pyproject.toml)
37+
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
38+
run: uv run mypy src/reynir
3539
- name: Test with pytest
3640
run: uv run pytest
3741
- name: Slack notification

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ dev = [
5858
"pytest",
5959
"ruff",
6060
"mypy; implementation_name != 'pypy'",
61+
"types-cffi",
6162
"setuptools",
6263
]
6364

src/reynir/bindb.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ def lookup_name_gender(self, name: str, preferred_case: str = "nf") -> str:
131131

132132
# The first name was not found: check whether the full name is
133133
# in the static phrases
134-
m = StaticPhrases.lookup(name)
135-
if m is not None:
136-
if m.fl in PERSON_NAME_FL:
137-
return m.ordfl
134+
sp = StaticPhrases.lookup(name)
135+
if sp is not None:
136+
if sp.fl in PERSON_NAME_FL:
137+
return sp.ordfl
138138
return "hk" # Unknown gender

src/reynir/reynir.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def __init__(self, job: "_Job", s: TokenList) -> None:
131131
self._err_index: Optional[int] = None
132132
self._error: Optional[ParseError] = None
133133
self._simplified_tree: Optional[SimpleTree] = None
134-
self._tree = None
134+
self._tree: Optional[Node] = None
135135
# Number of possible combinations
136136
self._num: Optional[int] = None
137137
# Score of best parse tree
@@ -154,7 +154,7 @@ def parse(self) -> bool:
154154
job = self._job
155155
num = 0
156156
score = 0
157-
tree = None
157+
tree: Optional[Node] = None
158158
try:
159159
# Invoke the parser on the sentence tokens
160160
tree, num, score = job.parse(self._s)

uv.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)