]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
mkosi/kmod: add typing info to make mypy happy 3531/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 14 Mar 2025 10:31:43 +0000 (11:31 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 14 Mar 2025 10:43:33 +0000 (11:43 +0100)
mkosi/kmod.py
tests/test_kmod.py

index 1c6e53266e719a05a8a5a51cecf8443f8f79cb84..88240a09994a555c4472927cd933a3d2367b796a 100644 (file)
@@ -6,7 +6,7 @@ import logging
 import os
 import re
 import subprocess
-from collections.abc import Iterable, Iterator
+from collections.abc import Iterable, Iterator, Reversible
 from pathlib import Path
 
 from mkosi.context import Context
@@ -23,7 +23,12 @@ def loaded_modules() -> list[str]:
     ]
 
 
-def globs_match_filename(name, globs, *, match_default: bool = False) -> bool:
+def globs_match_filename(
+    name: str,
+    globs: Reversible[str],
+    *,
+    match_default: bool = False,
+) -> bool:
     # Check whether the path matches any of the globs
 
     for glob in reversed(globs):
@@ -48,14 +53,22 @@ def globs_match_filename(name, globs, *, match_default: bool = False) -> bool:
     return match_default
 
 
-def globs_match_module(name, globs) -> bool:
+def globs_match_module(
+    name: str,
+    globs: Reversible[str],
+) -> bool:
     # Strip '.ko' suffix and an optional compression suffix
     name = re.sub(r"\.ko(\.(gz|xz|zst))?$", "", name)
     # Check whether the suffixless-path matches any of the globs
     return globs_match_filename(name, globs)
 
 
-def globs_match_firmware(name, globs, *, match_default: bool = False) -> bool:
+def globs_match_firmware(
+    name: str,
+    globs: Reversible[str],
+    *,
+    match_default: bool = False,
+) -> bool:
     # Strip any known compression suffixes
     name = re.sub(r"\.(gz|xz|zst)$", "", name)
     # Check whether the suffixless-path matches any of the globs
index d1b3a324a11f60336f4d74285bd659c839cc40b2..c7e127d4702163b4272774fbac7f262d663cdd94 100644 (file)
@@ -3,7 +3,7 @@
 from mkosi import kmod
 
 
-def test_globs_match_module():
+def test_globs_match_module() -> None:
     assert kmod.globs_match_module("drivers/ata/ahci.ko.xz", ["ahci"])
     assert not kmod.globs_match_module("drivers/ata/ahci.ko.xz.2", ["ahci"])
     assert not kmod.globs_match_module("drivers/ata/ahci.ko.xz", ["ata"])
@@ -41,7 +41,7 @@ def test_globs_match_module():
     assert not kmod.globs_match_module("drivers/ata/ahci.ko.xz", ["-*"])
 
 
-def test_normalize_module_glob():
+def test_normalize_module_glob() -> None:
     assert kmod.normalize_module_glob("raid[0-9]") == "raid[0-9]"
     assert kmod.normalize_module_glob("raid[0_9]") == "raid[0_9]"
     assert kmod.normalize_module_glob("raid[0_9]a_z") == "raid[0_9]a-z"