Replace some Any instances with specific type hints (#2950)
This commit is contained in:
parent
8646c9aac2
commit
f314b7be54
|
|
@ -6,7 +6,7 @@ import os
|
||||||
import time
|
import time
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Literal
|
from typing import Literal, overload
|
||||||
|
|
||||||
from parted import Device, Disk, DiskException, FileSystem, Geometry, IOException, Partition, PartitionException, freshDisk, getAllDevices, getDevice, newDisk
|
from parted import Device, Disk, DiskException, FileSystem, Geometry, IOException, Partition, PartitionException, freshDisk, getAllDevices, getDevice, newDisk
|
||||||
|
|
||||||
|
|
@ -351,7 +351,7 @@ class DeviceHandler:
|
||||||
self,
|
self,
|
||||||
cmd: str,
|
cmd: str,
|
||||||
info_type: Literal['lv', 'vg', 'pvseg']
|
info_type: Literal['lv', 'vg', 'pvseg']
|
||||||
) -> Any | None:
|
) -> LvmVolumeInfo | LvmGroupInfo | LvmPVInfo | None:
|
||||||
raw_info = SysCommand(cmd).decode().split('\n')
|
raw_info = SysCommand(cmd).decode().split('\n')
|
||||||
|
|
||||||
# for whatever reason the output sometimes contains
|
# for whatever reason the output sometimes contains
|
||||||
|
|
@ -389,7 +389,23 @@ class DeviceHandler:
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _lvm_info_with_retry(self, cmd: str, info_type: Literal['lv', 'vg', 'pvseg']) -> Any | None:
|
@overload
|
||||||
|
def _lvm_info_with_retry(self, cmd: str, info_type: Literal['lv']) -> LvmVolumeInfo | None:
|
||||||
|
...
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def _lvm_info_with_retry(self, cmd: str, info_type: Literal['vg']) -> LvmGroupInfo | None:
|
||||||
|
...
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def _lvm_info_with_retry(self, cmd: str, info_type: Literal['pvseg']) -> LvmPVInfo | None:
|
||||||
|
...
|
||||||
|
|
||||||
|
def _lvm_info_with_retry(
|
||||||
|
self,
|
||||||
|
cmd: str,
|
||||||
|
info_type: Literal['lv', 'vg', 'pvseg']
|
||||||
|
) -> LvmVolumeInfo | LvmGroupInfo | LvmPVInfo | None:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
return self._lvm_info(cmd, info_type)
|
return self._lvm_info(cmd, info_type)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from archinstall.lib.menu.menu_helper import MenuHelper
|
from archinstall.lib.menu.menu_helper import MenuHelper
|
||||||
from archinstall.tui import Alignment, FrameProperties, MenuItem, MenuItemGroup, Orientation, PreviewStyle, ResultType, SelectMenu
|
from archinstall.tui import Alignment, FrameProperties, MenuItem, MenuItemGroup, Orientation, PreviewStyle, ResultType, SelectMenu
|
||||||
|
|
@ -471,7 +471,7 @@ def suggest_multi_disk_layout(
|
||||||
delta = device.device_info.total_size - desired_root_partition_size
|
delta = device.device_info.total_size - desired_root_partition_size
|
||||||
devices_delta[device] = delta
|
devices_delta[device] = delta
|
||||||
|
|
||||||
sorted_delta: list[tuple[disk.BDevice, Any]] = sorted(devices_delta.items(), key=lambda x: x[1])
|
sorted_delta: list[tuple[disk.BDevice, disk.Size]] = sorted(devices_delta.items(), key=lambda x: x[1])
|
||||||
root_device: disk.BDevice | None = sorted_delta[0][0]
|
root_device: disk.BDevice | None = sorted_delta[0][0]
|
||||||
|
|
||||||
if home_device is None or root_device is None:
|
if home_device is None or root_device is None:
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from ...default_profiles.applications.pipewire import PipewireProfile
|
from ...default_profiles.applications.pipewire import PipewireProfile
|
||||||
from ..hardware import SysInfo
|
from ..hardware import SysInfo
|
||||||
|
from ..installer import Installer
|
||||||
from ..output import info
|
from ..output import info
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -18,20 +18,20 @@ class Audio(Enum):
|
||||||
class AudioConfiguration:
|
class AudioConfiguration:
|
||||||
audio: Audio
|
audio: Audio
|
||||||
|
|
||||||
def json(self) -> dict[str, Any]:
|
def json(self) -> dict[str, str]:
|
||||||
return {
|
return {
|
||||||
'audio': self.audio.value
|
'audio': self.audio.value
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_arg(arg: dict[str, Any]) -> 'AudioConfiguration':
|
def parse_arg(arg: dict[str, str]) -> 'AudioConfiguration':
|
||||||
return AudioConfiguration(
|
return AudioConfiguration(
|
||||||
Audio(arg['audio'])
|
Audio(arg['audio'])
|
||||||
)
|
)
|
||||||
|
|
||||||
def install_audio_config(
|
def install_audio_config(
|
||||||
self,
|
self,
|
||||||
installation: Any
|
installation: Installer
|
||||||
) -> None:
|
) -> None:
|
||||||
info(f'Installing audio server: {self.audio.name}')
|
info(f'Installing audio server: {self.audio.name}')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import dataclasses
|
import dataclasses
|
||||||
import json
|
import json
|
||||||
import ssl
|
import ssl
|
||||||
from typing import Any
|
|
||||||
from urllib.error import HTTPError
|
from urllib.error import HTTPError
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
from urllib.response import addinfourl
|
||||||
|
|
||||||
from ..exceptions import PackageError, SysCallError
|
from ..exceptions import PackageError, SysCallError
|
||||||
from ..models.gen import LocalPackage, PackageSearch, PackageSearchResult
|
from ..models.gen import LocalPackage, PackageSearch, PackageSearchResult
|
||||||
|
|
@ -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[str, str]) -> Any:
|
def _make_request(url: str, params: dict[str, str]) -> addinfourl:
|
||||||
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
|
||||||
|
|
@ -77,7 +77,7 @@ def find_package(package: str) -> list[PackageSearchResult]:
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def find_packages(*names: str) -> dict[str, Any]:
|
def find_packages(*names: str) -> dict[str, PackageSearchResult]:
|
||||||
"""
|
"""
|
||||||
This function returns the search results for many packages.
|
This function returns the search results for many packages.
|
||||||
The function itself is rather slow, so consider not sending to
|
The function itself is rather slow, so consider not sending to
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ class TranslationHandler:
|
||||||
languages = []
|
languages = []
|
||||||
|
|
||||||
for short_form in defined_languages:
|
for short_form in defined_languages:
|
||||||
mapping_entry: dict[str, Any] = next(filter(lambda x: x['abbr'] == short_form, mappings))
|
mapping_entry: dict[str, str] = next(filter(lambda x: x['abbr'] == short_form, mappings))
|
||||||
abbr = mapping_entry['abbr']
|
abbr = mapping_entry['abbr']
|
||||||
lang = mapping_entry['lang']
|
lang = mapping_entry['lang']
|
||||||
translated_lang = mapping_entry.get('translated_lang', None)
|
translated_lang = mapping_entry.get('translated_lang', None)
|
||||||
|
|
@ -95,7 +95,7 @@ class TranslationHandler:
|
||||||
except Exception:
|
except Exception:
|
||||||
error(f'Unable to set font {font}')
|
error(f'Unable to set font {font}')
|
||||||
|
|
||||||
def _load_language_mappings(self) -> list[dict[str, Any]]:
|
def _load_language_mappings(self) -> list[dict[str, str]]:
|
||||||
"""
|
"""
|
||||||
Load the mapping table of all known languages
|
Load the mapping table of all known languages
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,14 @@ disallow_untyped_defs = false
|
||||||
warn_return_any = false
|
warn_return_any = false
|
||||||
warn_unreachable = false
|
warn_unreachable = false
|
||||||
|
|
||||||
|
[[tool.mypy.overrides]]
|
||||||
|
module = "archinstall.lib.packages"
|
||||||
|
disallow_any_explicit = true
|
||||||
|
|
||||||
|
[[tool.mypy.overrides]]
|
||||||
|
module = "archinstall.lib.utils"
|
||||||
|
disallow_any_explicit = true
|
||||||
|
|
||||||
[[tool.mypy.overrides]]
|
[[tool.mypy.overrides]]
|
||||||
module = "archinstall.scripts.*"
|
module = "archinstall.scripts.*"
|
||||||
warn_unreachable = false
|
warn_unreachable = false
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue