From d28839137123b0418245a784432dea53a861157e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 14 Mar 2025 11:31:43 +0100 Subject: [PATCH] mkosi/kmod: add typing info to make mypy happy --- mkosi/kmod.py | 21 +++++++++++++++++---- tests/test_kmod.py | 4 ++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/mkosi/kmod.py b/mkosi/kmod.py index 1c6e53266..88240a099 100644 --- a/mkosi/kmod.py +++ b/mkosi/kmod.py @@ -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 diff --git a/tests/test_kmod.py b/tests/test_kmod.py index d1b3a324a..c7e127d47 100644 --- a/tests/test_kmod.py +++ b/tests/test_kmod.py @@ -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" -- 2.47.2