Skip to content

Commit 59e9fd4

Browse files
committed
checks.git: add type annotations
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent c81bc6c commit 59e9fd4

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

src/pkgcheck/checks/git.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class GitCommitsRepoSource(sources.RepoSource):
3434

3535
required_addons = (git.GitAddon,)
3636

37-
def __init__(self, options, git_addon):
37+
def __init__(self, options, git_addon: git.GitAddon):
3838
source = git_addon.commits_repo(git.GitChangedRepo)
3939
super().__init__(options, source)
4040

@@ -49,7 +49,7 @@ class GitCommitsSource(sources.Source):
4949
scope = base.commit_scope
5050
required_addons = (git.GitAddon,)
5151

52-
def __init__(self, *args, git_addon):
52+
def __init__(self, *args, git_addon: git.GitAddon):
5353
super().__init__(*args, source=git_addon.commits())
5454

5555

@@ -100,9 +100,7 @@ def __init__(self, keywords, commit, **kwargs):
100100
def desc(self):
101101
s = pluralism(self.keywords)
102102
keywords = ", ".join(self.keywords)
103-
return (
104-
f"commit {self.commit} (or later) dropped {self._status} " f"keyword{s}: [ {keywords} ]"
105-
)
103+
return f"commit {self.commit} (or later) dropped {self._status} keyword{s}: [ {keywords} ]"
106104

107105

108106
class DroppedUnstableKeywords(_DroppedKeywords, results.Error):
@@ -243,11 +241,11 @@ class GitPkgCommitsCheck(GentooRepoCheck, GitCommitsCheck):
243241
# package categories that are committed with stable keywords
244242
allowed_direct_stable = frozenset(["acct-user", "acct-group"])
245243

246-
def __init__(self, *args, git_addon):
244+
def __init__(self, *args, git_addon: git.GitAddon):
247245
super().__init__(*args)
248246
self.today = datetime.today()
249247
self.repo = self.options.target_repo
250-
self.valid_arches = self.options.target_repo.known_arches
248+
self.valid_arches: frozenset[str] = self.options.target_repo.known_arches
251249
self._git_addon = git_addon
252250
self._cleanup = []
253251

@@ -280,7 +278,7 @@ def removal_checks(self, pkgs):
280278
old_keywords = set().union(*(p.keywords for p in removal_repo.match(pkg.unversioned_atom)))
281279
new_keywords = set().union(*(p.keywords for p in self.repo.match(pkg.unversioned_atom)))
282280

283-
dropped_keywords = old_keywords - new_keywords
281+
dropped_keywords: set[str] = old_keywords - new_keywords
284282
dropped_stable_keywords = dropped_keywords & self.valid_arches
285283
dropped_unstable_keywords = set()
286284
for keyword in (x for x in dropped_keywords if x[0] == "~"):
@@ -482,7 +480,7 @@ def desc(self):
482480
return f"commit {self.commit}, {self.error}: {self.summary!r}"
483481

484482

485-
def verify_tags(*tags, required=False):
483+
def verify_tags(*tags: str, required: bool = False):
486484
"""Decorator to register commit tag verification methods."""
487485

488486
class decorator:
@@ -534,21 +532,20 @@ def __init__(self, *args):
534532
)
535533

536534
@verify_tags("Signed-off-by", required=True)
537-
def _signed_off_by_tag(self, tag, values, commit):
535+
def _signed_off_by_tag(self, tag: str, values: list[str], commit: git.GitCommit):
538536
"""Verify commit contains all required sign offs in accordance with GLEP 76."""
539537
required_sign_offs = {commit.author, commit.committer}
540-
missing_sign_offs = required_sign_offs.difference(values)
541-
if missing_sign_offs:
538+
if missing_sign_offs := required_sign_offs.difference(values):
542539
yield MissingSignOff(sorted(missing_sign_offs), commit=commit)
543540

544541
@verify_tags("Gentoo-Bug")
545-
def _deprecated_tag(self, tag, values, commit):
542+
def _deprecated_tag(self, tag: str, values: list[str], commit: git.GitCommit):
546543
"""Flag deprecated tags that shouldn't be used."""
547544
for value in values:
548545
yield InvalidCommitTag(tag, value, f"{tag} tag is no longer valid", commit=commit)
549546

550547
@verify_tags("Bug", "Closes")
551-
def _bug_tag(self, tag, values, commit):
548+
def _bug_tag(self, tag: str, values: list[str], commit: git.GitCommit):
552549
"""Verify values are URLs for Bug/Closes tags."""
553550
for value in values:
554551
parsed = urlparse(value)
@@ -574,7 +571,7 @@ def git_cat_file(self):
574571
)
575572

576573
@verify_tags("Fixes", "Reverts")
577-
def _commit_tag(self, tag, values, commit):
574+
def _commit_tag(self, tag, values, commit: git.GitCommit):
578575
"""Verify referenced commits exist for Fixes/Reverts tags."""
579576
self.git_cat_file.stdin.write("\n".join(values) + "\n")
580577
if self.git_cat_file.poll() is None:
@@ -586,7 +583,7 @@ def _commit_tag(self, tag, values, commit):
586583
if not status.startswith("commit "):
587584
yield InvalidCommitTag(tag, value, f"{status} commit", commit=commit)
588585

589-
def feed(self, commit):
586+
def feed(self, commit: git.GitCommit):
590587
if len(commit.message) == 0:
591588
yield InvalidCommitMessage("no commit message", commit=commit)
592589
return

0 commit comments

Comments
 (0)