Skip to content

Commit 32a268f

Browse files
committed
Add type checking step to CI and update type hints in code
1 parent afaaf2f commit 32a268f

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ jobs:
3636
- name: Check for code errors
3737
run: uv run ruff check .
3838

39+
- name: Type check with ty
40+
run: uv run ty check
41+
3942
- name: Run tests with pytest
4043
run: |
4144
uv run pytest tests/ -v --cov=. --cov-report=term-missing

flathub.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import urllib.parse
1212
import urllib.request
1313

14-
from gi.repository import GLib
14+
from gi.repository import GLib # type: ignore[import-untyped]
1515

1616

1717
def load_cache(path):
@@ -29,8 +29,8 @@ def load_cache(path):
2929

3030
class CommitCache:
3131
def __init__(self, commit_map):
32-
self.commit_map: dict[str, list[str | None]] = commit_map
33-
self.dirtree_map: dict[str | None] = {}
32+
self.commit_map: dict[str | None, list[str | None]] = commit_map
33+
self.dirtree_map: dict[str | None, str | None] = {}
3434
self.modified = False
3535

3636
# Backwards compat, re-resolve all commits where we don't have root dirtree info
@@ -74,7 +74,7 @@ def update_from_summary(self, branch: str):
7474
if commit and not self.has_commit(commit):
7575
self.update_for_commit(commit, branch)
7676

77-
def update_for_commit(self, commit: str | None, known_branch: str | None = None):
77+
def update_for_commit(self, commit: str, known_branch: str | None = None):
7878
ref = known_branch
7979
root_dirtree = None
8080
url = f"https://dl.flathub.org/repo/objects/{commit[0:2]}/{commit[2:]}.commit"
@@ -200,7 +200,10 @@ def parse_log(logname: str, cache: CommitCache, ignore_deltas=False):
200200
if first_line == "":
201201
return []
202202

203-
match = fastly_log_re.match(first_line)
203+
first_line_str = (
204+
first_line.decode("utf-8") if isinstance(first_line, bytes) else first_line
205+
)
206+
match = fastly_log_re.match(first_line_str)
204207
if match:
205208
line_re = fastly_log_re
206209
else:
@@ -219,7 +222,8 @@ def parse_log(logname: str, cache: CommitCache, ignore_deltas=False):
219222

220223
if line == "":
221224
break
222-
match = line_re.match(line)
225+
line_str = line.decode("utf-8") if isinstance(line, bytes) else line
226+
match = line_re.match(line_str)
223227
if not match:
224228
sys.stderr.write(f"Warning: Can't match line: {line[:-1]}\n")
225229
continue
@@ -229,7 +233,7 @@ def parse_log(logname: str, cache: CommitCache, ignore_deltas=False):
229233
if op != "GET" or result != "200":
230234
continue
231235

232-
target_ref: str = match.group(10)
236+
target_ref: str | None = match.group(10)
233237
if len(target_ref) == 0:
234238
target_ref = None
235239

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies = [
1414
dev = [
1515
"faker>=37.0.0",
1616
"ruff>=0.11.0",
17+
"ty>=0.0.3",
1718
]
1819
test = [
1920
"pytest>=8.0.0",

uv.lock

Lines changed: 27 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)