From f2e898090c503a685a7cdebed310a13ff7b8a472 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Wed, 22 Jul 2026 19:17:35 -0700 Subject: [PATCH] mypy: Add support for version 2.1 Tests: - Unit tests pass. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/cfg.py | 17 +++++++++-------- plinth/modules/diagnostics/__init__.py | 3 ++- plinth/modules/storage/udisks2.py | 3 ++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/plinth/cfg.py b/plinth/cfg.py index d95ff07dc..0dc0629a3 100644 --- a/plinth/cfg.py +++ b/plinth/cfg.py @@ -45,10 +45,10 @@ box_name = 'FreedomBox' # Other globals develop = False -config_files = [] +config_files: list[str] = [] -def expand_to_dot_d_paths(file_paths): +def expand_to_dot_d_paths(file_paths: list[str]) -> list[str]: """Expand a list of file paths to include file.d/* also.""" final_list = [] for file_path in file_paths: @@ -65,7 +65,7 @@ def expand_to_dot_d_paths(file_paths): return final_list -def get_develop_config_path(): +def get_develop_config_path() -> str: """Return config path of current source folder for development mode.""" root_directory = os.path.dirname(os.path.realpath(__file__)) root_directory = os.path.realpath(root_directory) @@ -73,7 +73,7 @@ def get_develop_config_path(): return config_path -def get_config_paths(): +def get_config_paths() -> list[str]: """Get default config paths.""" return [ '/usr/share/freedombox/freedombox.config', @@ -82,14 +82,14 @@ def get_config_paths(): ] -def read(): +def read() -> None: """Read all configuration files.""" config_paths = get_config_paths() for config_path in expand_to_dot_d_paths(config_paths): read_file(config_path) -def read_file(config_path): +def read_file(config_path: str): """Read and merge into defaults a single configuration file.""" if not os.path.isfile(config_path): # Does not throw exceptions # Ignore missing configuration files @@ -101,9 +101,9 @@ def read_file(config_path): parser = configparser.ConfigParser( defaults={ 'parent_dir': - pathlib.Path(config_path).parent.resolve(), + str(pathlib.Path(config_path).parent.resolve()), 'parent_parent_dir': - pathlib.Path(config_path).parent.parent.resolve(), + str(pathlib.Path(config_path).parent.parent.resolve()), }) parser.read(config_path) # Ignores all read errors @@ -123,6 +123,7 @@ def read_file(config_path): ) for section, name, datatype in config_items: + value: int | str | bool try: value = parser.get(section, name) except (configparser.NoSectionError, configparser.NoOptionError): diff --git a/plinth/modules/diagnostics/__init__.py b/plinth/modules/diagnostics/__init__.py index 21248f58d..5163c7940 100644 --- a/plinth/modules/diagnostics/__init__.py +++ b/plinth/modules/diagnostics/__init__.py @@ -9,6 +9,7 @@ import logging import pathlib import threading from copy import deepcopy +from typing import Any import psutil from django.urls import reverse_lazy @@ -40,7 +41,7 @@ _description = [ logger = logging.Logger(__name__) -current_results = {} +current_results: dict[str, Any] = {} results_lock = threading.Lock() diff --git a/plinth/modules/storage/udisks2.py b/plinth/modules/storage/udisks2.py index 0a19008e9..6b5f2d704 100644 --- a/plinth/modules/storage/udisks2.py +++ b/plinth/modules/storage/udisks2.py @@ -3,6 +3,7 @@ import logging import threading +from typing import Any from plinth import cfg from plinth.utils import import_from_gi @@ -40,7 +41,7 @@ _ERRORS: dict[str, str] = { 'Failed': 'org.freedesktop.UDisks2.Error.Failed', } -_jobs = {} +_jobs: dict[str, Any] = {} logger = logging.getLogger(__name__)