Skip to content

Commit e7f2a8c

Browse files
authored
Fix some mypy warnings in archinstall/lib/ (archlinux#3103)
1 parent 22b410d commit e7f2a8c

File tree

12 files changed

+37
-21
lines changed

12 files changed

+37
-21
lines changed

archinstall/lib/args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def _read_file(self, path: Path) -> str:
326326

327327
return path.read_text()
328328

329-
def _cleanup_config(self, config: Namespace | dict) -> dict[str, Any]:
329+
def _cleanup_config(self, config: Namespace | dict[str, Any]) -> dict[str, Any]:
330330
clean_args = {}
331331
for key, val in config.items():
332332
if isinstance(val, dict):

archinstall/lib/configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
class ConfigurationOutput:
23-
def __init__(self, config: dict):
23+
def __init__(self, config: dict[str, Any]):
2424
"""
2525
Configuration output handler to parse the existing configuration data structure and prepare for output on the
2626
console and for saving it to configuration files

archinstall/lib/disk/device_model.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,17 @@ def __le__(self, other: Size) -> bool:
439439
return self._normalize() <= other._normalize()
440440

441441
@override
442-
def __eq__(self, other) -> bool:
442+
def __eq__(self, other: object) -> bool:
443+
if not isinstance(other, Size):
444+
return NotImplemented
445+
443446
return self._normalize() == other._normalize()
444447

445448
@override
446-
def __ne__(self, other) -> bool:
449+
def __ne__(self, other: object) -> bool:
450+
if not isinstance(other, Size):
451+
return NotImplemented
452+
447453
return self._normalize() != other._normalize()
448454

449455
def __gt__(self, other: Size) -> bool:

archinstall/lib/general.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def run_custom_user_commands(commands: list[str], installation: Installer) -> No
477477
os.unlink(chroot_path)
478478

479479

480-
def json_stream_to_structure(configuration_identifier: str, stream: str, target: dict) -> bool:
480+
def json_stream_to_structure(configuration_identifier: str, stream: str, target: dict[str, Any]) -> bool:
481481
"""
482482
Load a JSON encoded dictionary from a stream and merge it into an existing dictionary.
483483
A stream can be a filepath, a URL or a raw JSON string.

archinstall/lib/installer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(
7272
if accessibility_tools_in_use():
7373
self._base_packages.extend(__accessibility_packages__)
7474

75-
self.post_base_install: list[Callable] = []
75+
self.post_base_install: list[Callable] = [] # type: ignore[type-arg]
7676

7777
# TODO: Figure out which one of these two we'll use.. But currently we're mixing them..
7878
storage['session'] = self

archinstall/lib/models/gen.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ def pkg_version(self) -> str:
4040
return self.pkgver
4141

4242
@override
43-
def __eq__(self, other) -> bool:
43+
def __eq__(self, other: object) -> bool:
44+
if not isinstance(other, PackageSearchResult):
45+
return NotImplemented
46+
4447
return self.pkg_version == other.pkg_version
4548

4649
def __lt__(self, other: 'PackageSearchResult') -> bool:
@@ -99,7 +102,10 @@ def pkg_version(self) -> str:
99102
return self.version
100103

101104
@override
102-
def __eq__(self, other) -> bool:
105+
def __eq__(self, other: object) -> bool:
106+
if not isinstance(other, LocalPackage):
107+
return NotImplemented
108+
103109
return self.pkg_version == other.pkg_version
104110

105111
def __lt__(self, other: 'LocalPackage') -> bool:

archinstall/lib/models/mirrors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def speed(self) -> float:
5757
with urllib.request.urlopen(req, None, 5) as handle, DownloadTimer(timeout=5) as timer:
5858
size = len(handle.read())
5959

60+
assert timer.time is not None
6061
self._speed = size / timer.time
6162
debug(f" speed: {self._speed} ({int(self._speed / 1024 / 1024 * 100) / 100}MiB/s)")
6263
# Do not retry error

archinstall/lib/models/users.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def _parse(cls, config_users: list[dict[str, Any]]) -> list['User']:
140140
return users
141141

142142
@classmethod
143-
def _parse_backwards_compatible(cls, config_users: dict, sudo: bool) -> list['User']:
143+
def _parse_backwards_compatible(cls, config_users: dict[str, dict[str, str]], sudo: bool) -> list['User']:
144144
if len(config_users.keys()) > 0:
145145
username = list(config_users.keys())[0]
146146
password = config_users[username]['!password']
@@ -153,8 +153,8 @@ def _parse_backwards_compatible(cls, config_users: dict, sudo: bool) -> list['Us
153153
@classmethod
154154
def parse_arguments(
155155
cls,
156-
config_users: list[dict[str, str]] | dict[str, str],
157-
config_superusers: list[dict[str, str]] | dict[str, str]
156+
config_users: list[dict[str, str]] | dict[str, dict[str, str]],
157+
config_superusers: list[dict[str, str]] | dict[str, dict[str, str]]
158158
) -> list['User']:
159159
users = []
160160

archinstall/lib/networking.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import ssl
77
import struct
88
import time
9-
from types import FrameType
10-
from typing import Any
9+
from types import FrameType, TracebackType
10+
from typing import Any, Self
1111
from urllib.error import URLError
1212
from urllib.parse import urlencode
1313
from urllib.request import urlopen
@@ -40,15 +40,15 @@ def raise_timeout(self, signl: int, frame: FrameType | None) -> None:
4040
'''
4141
raise DownloadTimeout(f'Download timed out after {self.timeout} second(s).')
4242

43-
def __enter__(self):
43+
def __enter__(self) -> Self:
4444
if self.timeout > 0:
4545
self.previous_handler = signal.signal(signal.SIGALRM, self.raise_timeout) # type: ignore[assignment]
4646
self.previous_timer = signal.alarm(self.timeout)
4747

4848
self.start_time = time.time()
4949
return self
5050

51-
def __exit__(self, typ, value, traceback) -> None:
51+
def __exit__(self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None) -> None:
5252
if self.start_time:
5353
time_delta = time.time() - self.start_time
5454
signal.alarm(0)
@@ -164,7 +164,7 @@ def build_icmp(payload: bytes) -> bytes:
164164
return struct.pack('!BBHHH', 8, 0, checksum, 0, 1) + payload
165165

166166

167-
def ping(hostname, timeout=5) -> int:
167+
def ping(hostname, timeout: int = 5) -> int:
168168
watchdog = select.epoll()
169169
started = time.time()
170170
random_identifier = f'archinstall-{random.randint(1000, 9999)}'.encode()

archinstall/lib/output.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class FormattedOutput:
2020
def _get_values(
2121
cls,
2222
o: 'DataclassInstance',
23-
class_formatter: str | Callable | None = None,
23+
class_formatter: str | Callable | None = None, # type: ignore[type-arg]
2424
filter_list: list[str] = []
2525
) -> dict[str, Any]:
2626
"""
@@ -52,7 +52,7 @@ def _get_values(
5252
def as_table(
5353
cls,
5454
obj: list[Any],
55-
class_formatter: str | Callable | None = None,
55+
class_formatter: str | Callable | None = None, # type: ignore[type-arg]
5656
filter_list: list[str] = [],
5757
capitalize: bool = False
5858
) -> str:

0 commit comments

Comments
 (0)