Skip to content

Commit ae0d94a

Browse files
committed
Replace some Any instances with specific type hints
1 parent 8646c9a commit ae0d94a

File tree

6 files changed

+38
-14
lines changed

6 files changed

+38
-14
lines changed

archinstall/lib/disk/device_handler.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import time
77
from collections.abc import Iterable
88
from pathlib import Path
9-
from typing import Any, Literal
9+
from typing import Literal, overload
1010

1111
from parted import Device, Disk, DiskException, FileSystem, Geometry, IOException, Partition, PartitionException, freshDisk, getAllDevices, getDevice, newDisk
1212

@@ -351,7 +351,7 @@ def _lvm_info(
351351
self,
352352
cmd: str,
353353
info_type: Literal['lv', 'vg', 'pvseg']
354-
) -> Any | None:
354+
) -> LvmVolumeInfo | LvmGroupInfo | LvmPVInfo | None:
355355
raw_info = SysCommand(cmd).decode().split('\n')
356356

357357
# for whatever reason the output sometimes contains
@@ -389,7 +389,23 @@ def _lvm_info(
389389

390390
return None
391391

392-
def _lvm_info_with_retry(self, cmd: str, info_type: Literal['lv', 'vg', 'pvseg']) -> Any | None:
392+
@overload
393+
def _lvm_info_with_retry(self, cmd: str, info_type: Literal['lv']) -> LvmVolumeInfo | None:
394+
...
395+
396+
@overload
397+
def _lvm_info_with_retry(self, cmd: str, info_type: Literal['vg']) -> LvmGroupInfo | None:
398+
...
399+
400+
@overload
401+
def _lvm_info_with_retry(self, cmd: str, info_type: Literal['pvseg']) -> LvmPVInfo | None:
402+
...
403+
404+
def _lvm_info_with_retry(
405+
self,
406+
cmd: str,
407+
info_type: Literal['lv', 'vg', 'pvseg']
408+
) -> LvmVolumeInfo | LvmGroupInfo | LvmPVInfo | None:
393409
while True:
394410
try:
395411
return self._lvm_info(cmd, info_type)

archinstall/lib/interactions/disk_conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from pathlib import Path
4-
from typing import TYPE_CHECKING, Any
4+
from typing import TYPE_CHECKING
55

66
from archinstall.lib.menu.menu_helper import MenuHelper
77
from archinstall.tui import Alignment, FrameProperties, MenuItem, MenuItemGroup, Orientation, PreviewStyle, ResultType, SelectMenu
@@ -471,7 +471,7 @@ def suggest_multi_disk_layout(
471471
delta = device.device_info.total_size - desired_root_partition_size
472472
devices_delta[device] = delta
473473

474-
sorted_delta: list[tuple[disk.BDevice, Any]] = sorted(devices_delta.items(), key=lambda x: x[1])
474+
sorted_delta: list[tuple[disk.BDevice, disk.Size]] = sorted(devices_delta.items(), key=lambda x: x[1])
475475
root_device: disk.BDevice | None = sorted_delta[0][0]
476476

477477
if home_device is None or root_device is None:

archinstall/lib/models/audio_configuration.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from dataclasses import dataclass
22
from enum import Enum
3-
from typing import Any
43

54
from ...default_profiles.applications.pipewire import PipewireProfile
65
from ..hardware import SysInfo
6+
from ..installer import Installer
77
from ..output import info
88

99

@@ -18,20 +18,20 @@ class Audio(Enum):
1818
class AudioConfiguration:
1919
audio: Audio
2020

21-
def json(self) -> dict[str, Any]:
21+
def json(self) -> dict[str, str]:
2222
return {
2323
'audio': self.audio.value
2424
}
2525

2626
@staticmethod
27-
def parse_arg(arg: dict[str, Any]) -> 'AudioConfiguration':
27+
def parse_arg(arg: dict[str, str]) -> 'AudioConfiguration':
2828
return AudioConfiguration(
2929
Audio(arg['audio'])
3030
)
3131

3232
def install_audio_config(
3333
self,
34-
installation: Any
34+
installation: Installer
3535
) -> None:
3636
info(f'Installing audio server: {self.audio.name}')
3737

archinstall/lib/packages/packages.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import dataclasses
22
import json
33
import ssl
4-
from typing import Any
54
from urllib.error import HTTPError
65
from urllib.parse import urlencode
76
from urllib.request import urlopen
7+
from urllib.response import addinfourl
88

99
from ..exceptions import PackageError, SysCallError
1010
from ..models.gen import LocalPackage, PackageSearch, PackageSearchResult
@@ -15,7 +15,7 @@
1515
BASE_GROUP_URL = 'https://archlinux.org/groups/search/json/'
1616

1717

18-
def _make_request(url: str, params: dict[str, str]) -> Any:
18+
def _make_request(url: str, params: dict[str, str]) -> addinfourl:
1919
ssl_context = ssl.create_default_context()
2020
ssl_context.check_hostname = False
2121
ssl_context.verify_mode = ssl.CERT_NONE
@@ -77,7 +77,7 @@ def find_package(package: str) -> list[PackageSearchResult]:
7777
return results
7878

7979

80-
def find_packages(*names: str) -> dict[str, Any]:
80+
def find_packages(*names: str) -> dict[str, PackageSearchResult]:
8181
"""
8282
This function returns the search results for many packages.
8383
The function itself is rather slow, so consider not sending to

archinstall/lib/translationhandler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _get_translations(self) -> list[Language]:
5959
languages = []
6060

6161
for short_form in defined_languages:
62-
mapping_entry: dict[str, Any] = next(filter(lambda x: x['abbr'] == short_form, mappings))
62+
mapping_entry: dict[str, str] = next(filter(lambda x: x['abbr'] == short_form, mappings))
6363
abbr = mapping_entry['abbr']
6464
lang = mapping_entry['lang']
6565
translated_lang = mapping_entry.get('translated_lang', None)
@@ -95,7 +95,7 @@ def _set_font(self, font: str) -> None:
9595
except Exception:
9696
error(f'Unable to set font {font}')
9797

98-
def _load_language_mappings(self) -> list[dict[str, Any]]:
98+
def _load_language_mappings(self) -> list[dict[str, str]]:
9999
"""
100100
Load the mapping table of all known languages
101101
"""

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ disallow_untyped_defs = false
107107
warn_return_any = false
108108
warn_unreachable = false
109109

110+
[[tool.mypy.overrides]]
111+
module = "archinstall.lib.packages"
112+
disallow_any_explicit = true
113+
114+
[[tool.mypy.overrides]]
115+
module = "archinstall.lib.utils"
116+
disallow_any_explicit = true
117+
110118
[[tool.mypy.overrides]]
111119
module = "archinstall.scripts.*"
112120
warn_unreachable = false

0 commit comments

Comments
 (0)