Fix some mypy warnings in the lib/ directory (#2822)

This commit is contained in:
correctmost 2024-11-16 02:27:26 -05:00 committed by GitHub
parent c682ddf391
commit ecad6762e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 16 additions and 14 deletions

View File

@ -7,6 +7,7 @@ import subprocess
import time import time
from collections.abc import Callable from collections.abc import Callable
from pathlib import Path from pathlib import Path
from types import TracebackType
from typing import Any, Optional, TYPE_CHECKING, Union from typing import Any, Optional, TYPE_CHECKING, Union
from . import disk from . import disk
@ -99,7 +100,7 @@ class Installer:
def __enter__(self) -> 'Installer': def __enter__(self) -> 'Installer':
return self return self
def __exit__(self, exc_type, exc_val, exc_tb) -> bool: def __exit__(self, exc_type: type[BaseException] | None, exc_val, exc_tb: TracebackType | None) -> bool:
if exc_type is not None: if exc_type is not None:
error(exc_val) error(exc_val)
@ -692,7 +693,7 @@ class Installer:
# If we haven't installed the base yet (function called pre-maturely) # If we haven't installed the base yet (function called pre-maturely)
if self.helper_flags.get('base', False) is False: if self.helper_flags.get('base', False) is False:
def post_install_enable_networkd_resolved(*args: str, **kwargs: str): def post_install_enable_networkd_resolved(*args: str, **kwargs: str) -> None:
self.enable_service(['systemd-networkd', 'systemd-resolved']) self.enable_service(['systemd-networkd', 'systemd-resolved'])
self.post_base_install.append(post_install_enable_networkd_resolved) self.post_base_install.append(post_install_enable_networkd_resolved)

View File

@ -23,8 +23,8 @@ class Selector:
display_func: Optional[Callable] = None, display_func: Optional[Callable] = None,
default: Optional[Any] = None, default: Optional[Any] = None,
enabled: bool = False, enabled: bool = False,
dependencies: list = [], dependencies: list[str] = [],
dependencies_not: list = [], dependencies_not: list[str] = [],
exec_func: Optional[Callable] = None, exec_func: Optional[Callable] = None,
preview_func: Optional[Callable] = None, preview_func: Optional[Callable] = None,
mandatory: bool = False, mandatory: bool = False,

View File

@ -156,5 +156,5 @@ class LocalPackage:
def __eq__(self, other) -> bool: def __eq__(self, other) -> bool:
return self.pkg_version == other.pkg_version return self.pkg_version == other.pkg_version
def __lt__(self, other) -> bool: def __lt__(self, other: 'LocalPackage') -> bool:
return self.pkg_version < other.pkg_version return self.pkg_version < other.pkg_version

View File

@ -6,6 +6,7 @@ import time
import select import select
import signal import signal
import random import random
from types import FrameType
from typing import Union, Any, Optional from typing import Union, Any, Optional
from urllib.error import URLError from urllib.error import URLError
from urllib.parse import urlencode from urllib.parse import urlencode
@ -34,7 +35,7 @@ class DownloadTimer():
self.previous_handler = None self.previous_handler = None
self.previous_timer: Optional[int] = None self.previous_timer: Optional[int] = None
def raise_timeout(self, signl, frame) -> None: def raise_timeout(self, signl: int, frame: FrameType | None) -> None:
''' '''
Raise the DownloadTimeout exception. Raise the DownloadTimeout exception.
''' '''
@ -119,7 +120,7 @@ def enrich_iface_types(interfaces: Union[dict[str, Any], list[str]]) -> dict[str
return result return result
def fetch_data_from_url(url: str, params: Optional[dict] = None) -> str: def fetch_data_from_url(url: str, params: Optional[dict[str, str]] = None) -> str:
ssl_context = ssl.create_default_context() ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE ssl_context.verify_mode = ssl.CERT_NONE
@ -140,7 +141,7 @@ def fetch_data_from_url(url: str, params: Optional[dict] = None) -> str:
raise ValueError(f'Unexpected error when parsing response: {e}') raise ValueError(f'Unexpected error when parsing response: {e}')
def calc_checksum(icmp_packet) -> int: def calc_checksum(icmp_packet: bytes) -> int:
# Calculate the ICMP checksum # Calculate the ICMP checksum
checksum = 0 checksum = 0
for i in range(0, len(icmp_packet), 2): for i in range(0, len(icmp_packet), 2):

View File

@ -15,7 +15,7 @@ BASE_URL_PKG_SEARCH = 'https://archlinux.org/packages/search/json/'
BASE_GROUP_URL = 'https://archlinux.org/groups/search/json/' BASE_GROUP_URL = 'https://archlinux.org/groups/search/json/'
def _make_request(url: str, params: dict) -> Any: def _make_request(url: str, params: dict[str, str]) -> Any:
ssl_context = ssl.create_default_context() ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE ssl_context.verify_mode = ssl.CERT_NONE
@ -91,7 +91,7 @@ def find_packages(*names: str) -> dict[str, Any]:
return result return result
def validate_package_list(packages: list) -> tuple[list, list]: def validate_package_list(packages: list[str]) -> tuple[list[str], list[str]]:
""" """
Validates a list of given packages. Validates a list of given packages.
return: Tuple of lists containing valid packavges in the first and invalid return: Tuple of lists containing valid packavges in the first and invalid

View File

@ -82,7 +82,7 @@ def _find_nth(haystack: list[str], needle: str, n: int) -> Optional[int]:
return None return None
def load_plugin(path: Path): def load_plugin(path: Path) -> None:
namespace: Optional[str] = None namespace: Optional[str] = None
parsed_url = urllib.parse.urlparse(str(path)) parsed_url = urllib.parse.urlparse(str(path))
info(f"Loading plugin from url {parsed_url}") info(f"Loading plugin from url {parsed_url}")

View File

@ -284,7 +284,7 @@ class ProfileHandler:
return profiles return profiles
def _verify_unique_profile_names(self, profiles: list[Profile]): def _verify_unique_profile_names(self, profiles: list[Profile]) -> None:
""" """
All profile names have to be unique, this function will verify All profile names have to be unique, this function will verify
that the provided list contains only default_profiles with unique names that the provided list contains only default_profiles with unique names
@ -348,7 +348,7 @@ class ProfileHandler:
self._verify_unique_profile_names(profiles) self._verify_unique_profile_names(profiles)
return profiles return profiles
def reset_top_level_profiles(self, exclude: list[Profile] = []): def reset_top_level_profiles(self, exclude: list[Profile] = []) -> None:
""" """
Reset all top level profile configurations, this is usually necessary Reset all top level profile configurations, this is usually necessary
when a new top level profile is selected when a new top level profile is selected

View File

@ -85,7 +85,7 @@ class TranslationHandler:
return languages return languages
def _set_font(self, font: str): def _set_font(self, font: str) -> None:
""" """
Set the provided font as the new terminal font Set the provided font as the new terminal font
""" """