Skip to content

Commit c3818e2

Browse files
committed
Remove some Any instances from the codebase
1 parent d9ac33d commit c3818e2

7 files changed

Lines changed: 61 additions & 29 deletions

File tree

archinstall/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import traceback
99
from argparse import ArgumentParser, Namespace
1010
from pathlib import Path
11-
from typing import TYPE_CHECKING, Any
11+
from typing import TYPE_CHECKING
1212

1313
from archinstall.lib.args import arch_config_handler
1414
from archinstall.lib.disk.utils import disk_layouts

archinstall/lib/installer.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
from .storage import storage
4646

4747
if TYPE_CHECKING:
48-
_: Any
48+
from archinstall.lib.translationhandler import DeferredTranslation
49+
50+
_: Callable[[str], DeferredTranslation]
4951

5052
# Any package that the Installer() is responsible for (optional and the default ones)
5153
__packages__ = ["base", "base-devel", "linux-firmware", "linux", "linux-lts", "linux-zen", "linux-hardened"]
@@ -80,7 +82,7 @@ def __init__(
8082

8183
self.init_time = time.strftime('%Y-%m-%d_%H-%M-%S')
8284
self.milliseconds = int(str(time.time()).split('.')[1])
83-
self.helper_flags: dict[str, Any] = {'base': False, 'bootloader': None}
85+
self.helper_flags: dict[str, str | bool | None] = {'base': False, 'bootloader': None}
8486

8587
for kernel in self.kernels:
8688
self._base_packages.append(kernel)
@@ -162,23 +164,21 @@ def _verify_service_stop(self) -> None:
162164
"""
163165

164166
if not arch_config_handler.args.skip_ntp:
165-
info(_('Waiting for time sync (timedatectl show) to complete.'))
167+
info(str(_('Waiting for time sync (timedatectl show) to complete.')))
166168

167169
started_wait = time.time()
168170
notified = False
169171
while True:
170172
if not notified and time.time() - started_wait > 5:
171173
notified = True
172-
warn(
173-
_("Time synchronization not completing, while you wait - check the docs for workarounds: https://archinstall.readthedocs.io/"))
174+
warn(str(_("Time synchronization not completing, while you wait - check the docs for workarounds: https://archinstall.readthedocs.io/")))
174175

175176
time_val = SysCommand('timedatectl show --property=NTPSynchronized --value').decode()
176177
if time_val and time_val.strip() == 'yes':
177178
break
178179
time.sleep(1)
179180
else:
180-
info(
181-
_('Skipping waiting for automatic time sync (this can cause issues if time is out of sync during installation)'))
181+
info(str(_('Skipping waiting for automatic time sync (this can cause issues if time is out of sync during installation)')))
182182

183183
info('Waiting for automatic mirror selection (reflector) to complete.')
184184
while self._service_state('reflector') not in ('dead', 'failed', 'exited'):
@@ -188,7 +188,7 @@ def _verify_service_stop(self) -> None:
188188
# while self._service_state('pacman-init') not in ('dead', 'failed', 'exited'):
189189
# time.sleep(1)
190190

191-
info(_('Waiting for Arch Linux keyring sync (archlinux-keyring-wkd-sync) to complete.'))
191+
info(str(_('Waiting for Arch Linux keyring sync (archlinux-keyring-wkd-sync) to complete.')))
192192
# Wait for the timer to kick in
193193
while self._service_started('archlinux-keyring-wkd-sync.timer') is None:
194194
time.sleep(1)

archinstall/lib/models/network_configuration.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
from dataclasses import dataclass, field
44
from enum import Enum
5-
from typing import TYPE_CHECKING, Any
5+
from typing import TYPE_CHECKING, NotRequired, TypedDict
66

77
from ..models.profile_model import ProfileConfiguration
88

99
if TYPE_CHECKING:
1010
from collections.abc import Callable
1111

12+
from archinstall.lib.installer import Installer
1213
from archinstall.lib.translationhandler import DeferredTranslation
1314

1415
_: Callable[[str], DeferredTranslation]
@@ -29,6 +30,14 @@ def display_msg(self) -> str:
2930
return str(_('Manual configuration'))
3031

3132

33+
class _NicSerialization(TypedDict):
34+
iface: str | None
35+
ip: str | None
36+
dhcp: bool
37+
gateway: str | None
38+
dns: list[str]
39+
40+
3241
@dataclass
3342
class Nic:
3443
iface: str | None = None
@@ -37,7 +46,7 @@ class Nic:
3746
gateway: str | None = None
3847
dns: list[str] = field(default_factory=list)
3948

40-
def table_data(self) -> dict[str, Any]:
49+
def table_data(self) -> dict[str, str | bool | list[str]]:
4150
return {
4251
'iface': self.iface if self.iface else '',
4352
'ip': self.ip if self.ip else '',
@@ -46,7 +55,7 @@ def table_data(self) -> dict[str, Any]:
4655
'dns': self.dns
4756
}
4857

49-
def json(self) -> dict[str, Any]:
58+
def json(self) -> _NicSerialization:
5059
return {
5160
'iface': self.iface,
5261
'ip': self.ip,
@@ -56,7 +65,7 @@ def json(self) -> dict[str, Any]:
5665
}
5766

5867
@staticmethod
59-
def parse_arg(arg: dict[str, Any]) -> Nic:
68+
def parse_arg(arg: _NicSerialization) -> Nic:
6069
return Nic(
6170
iface=arg.get('iface', None),
6271
ip=arg.get('ip', None),
@@ -93,20 +102,25 @@ def as_systemd_config(self) -> str:
93102
return config_str
94103

95104

105+
class _NetworkConfigurationSerialization(TypedDict):
106+
type: str
107+
nics: NotRequired[list[_NicSerialization]]
108+
109+
96110
@dataclass
97111
class NetworkConfiguration:
98112
type: NicType
99113
nics: list[Nic] = field(default_factory=list)
100114

101-
def json(self) -> dict[str, Any]:
102-
config: dict[str, Any] = {'type': self.type.value}
115+
def json(self) -> _NetworkConfigurationSerialization:
116+
config: _NetworkConfigurationSerialization = {'type': self.type.value}
103117
if self.nics:
104118
config['nics'] = [n.json() for n in self.nics]
105119

106120
return config
107121

108122
@staticmethod
109-
def parse_arg(config: dict[str, Any]) -> NetworkConfiguration | None:
123+
def parse_arg(config: _NetworkConfigurationSerialization) -> NetworkConfiguration | None:
110124
nic_type = config.get('type', None)
111125
if not nic_type:
112126
return None
@@ -126,7 +140,7 @@ def parse_arg(config: dict[str, Any]) -> NetworkConfiguration | None:
126140

127141
def install_network_config(
128142
self,
129-
installation: Any,
143+
installation: Installer,
130144
profile_config: ProfileConfiguration | None = None
131145
) -> None:
132146
match self.type:

archinstall/lib/models/profile_model.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
from __future__ import annotations
22

33
from dataclasses import dataclass
4-
from typing import Any
4+
from typing import TYPE_CHECKING, TypedDict
55

66
from archinstall.default_profiles.profile import GreeterType, Profile
77

88
from ..hardware import GfxDriver
99

10+
if TYPE_CHECKING:
11+
from archinstall.lib.profile.profiles_handler import ProfileSerialization
12+
13+
14+
class _ProfileConfigurationSerialization(TypedDict):
15+
profile: ProfileSerialization
16+
gfx_driver: str | None
17+
greeter: str | None
18+
1019

1120
@dataclass
1221
class ProfileConfiguration:
1322
profile: Profile | None = None
1423
gfx_driver: GfxDriver | None = None
1524
greeter: GreeterType | None = None
1625

17-
def json(self) -> dict[str, Any]:
26+
def json(self) -> _ProfileConfigurationSerialization:
1827
from ..profile.profiles_handler import profile_handler
1928
return {
2029
'profile': profile_handler.to_json(self.profile),
@@ -23,7 +32,7 @@ def json(self) -> dict[str, Any]:
2332
}
2433

2534
@classmethod
26-
def parse_arg(cls, arg: dict[str, Any]) -> 'ProfileConfiguration':
35+
def parse_arg(cls, arg: _ProfileConfigurationSerialization) -> 'ProfileConfiguration':
2736
from ..profile.profiles_handler import profile_handler
2837
profile = profile_handler.parse_profile_config(arg['profile'])
2938
greeter = arg.get('greeter', None)

archinstall/lib/models/users.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def groups(self) -> list[str]:
115115
# if it's every going to be used
116116
return []
117117

118-
def json(self) -> dict[str, Any]:
118+
def json(self) -> dict[str, str | bool]:
119119
return {
120120
'username': self.username,
121121
'!password': self.password,

archinstall/lib/pacman/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
from .repo import Repo
1414

1515
if TYPE_CHECKING:
16-
_: Any
16+
from archinstall.lib.translationhandler import DeferredTranslation
17+
18+
_: Callable[[str], DeferredTranslation]
1719

1820

1921
class Pacman:
@@ -33,14 +35,14 @@ def run(args: str, default_cmd: str = 'pacman') -> SysCommand:
3335
pacman_db_lock = Path('/var/lib/pacman/db.lck')
3436

3537
if pacman_db_lock.exists():
36-
warn(_('Pacman is already running, waiting maximum 10 minutes for it to terminate.'))
38+
warn(str(_('Pacman is already running, waiting maximum 10 minutes for it to terminate.')))
3739

3840
started = time.time()
3941
while pacman_db_lock.exists():
4042
time.sleep(0.25)
4143

4244
if time.time() - started > (60 * 10):
43-
error(_('Pre-existing pacman lock never exited. Please clean up any existing pacman sessions before using archinstall.'))
45+
error(str(_('Pre-existing pacman lock never exited. Please clean up any existing pacman sessions before using archinstall.')))
4446
exit(1)
4547

4648
return SysCommand(f'{default_cmd} {args}')

archinstall/lib/profile/profiles_handler.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pathlib import Path
99
from tempfile import NamedTemporaryFile
1010
from types import ModuleType
11-
from typing import TYPE_CHECKING, Any
11+
from typing import TYPE_CHECKING, NotRequired, TypedDict
1212

1313
from ...default_profiles.profile import GreeterType, Profile
1414
from ..hardware import GfxDriver
@@ -26,20 +26,27 @@
2626
_: Callable[[str], DeferredTranslation]
2727

2828

29+
class ProfileSerialization(TypedDict):
30+
main: NotRequired[str]
31+
details: NotRequired[list[str]]
32+
custom_settings: NotRequired[dict[str, dict[str, str | None]]]
33+
path: NotRequired[str]
34+
35+
2936
class ProfileHandler:
3037
def __init__(self) -> None:
3138
self._profiles: list[Profile] | None = None
3239

3340
# special variable to keep track of a profile url configuration
3441
# it is merely used to be able to export the path again when a user
3542
# wants to save the configuration
36-
self._url_path = None
43+
self._url_path: str | None = None
3744

38-
def to_json(self, profile: Profile | None) -> dict[str, Any]:
45+
def to_json(self, profile: Profile | None) -> ProfileSerialization:
3946
"""
4047
Serialize the selected profile setting to JSON
4148
"""
42-
data: dict[str, Any] = {}
49+
data: ProfileSerialization = {}
4350

4451
if profile is not None:
4552
data = {
@@ -53,7 +60,7 @@ def to_json(self, profile: Profile | None) -> dict[str, Any]:
5360

5461
return data
5562

56-
def parse_profile_config(self, profile_config: dict[str, Any]) -> Profile | None:
63+
def parse_profile_config(self, profile_config: ProfileSerialization) -> Profile | None:
5764
"""
5865
Deserialize JSON configuration for profile
5966
"""

0 commit comments

Comments
 (0)