From 6a6642a9c1e1a684524a43d99fe2099e8e00d8ad Mon Sep 17 00:00:00 2001 From: correctmost <134317971+correctmost@users.noreply.github.com> Date: Sat, 30 Nov 2024 17:17:10 -0500 Subject: [PATCH] Replace some Any instances with specific type hints (#2973) --- archinstall/default_profiles/profile.py | 10 +++++----- archinstall/default_profiles/xorg.py | 2 +- archinstall/lib/disk/device_model.py | 14 +++++++------- archinstall/lib/locale/locale_menu.py | 2 +- archinstall/tui/curses_menu.py | 4 ++-- pyproject.toml | 4 ---- 6 files changed, 16 insertions(+), 20 deletions(-) diff --git a/archinstall/default_profiles/profile.py b/archinstall/default_profiles/profile.py index cd88f873..c9a492f9 100644 --- a/archinstall/default_profiles/profile.py +++ b/archinstall/default_profiles/profile.py @@ -2,7 +2,7 @@ from __future__ import annotations import sys from enum import Enum, auto -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING from ..lib.storage import storage @@ -67,7 +67,7 @@ class Profile: self.name = name self.description = description self.profile_type = profile_type - self.custom_settings: dict[str, Any] = {} + self.custom_settings: dict[str, str | None] = {} self.advanced = advanced self._support_gfx_driver = support_gfx_driver @@ -124,7 +124,7 @@ class Profile: are needed """ - def json(self) -> dict[str, Any]: + def json(self) -> dict[str, str]: """ Returns a json representation of the profile """ @@ -136,7 +136,7 @@ class Profile: """ return SelectResult.NewSelection - def set_custom_settings(self, settings: dict[str, Any]) -> None: + def set_custom_settings(self, settings: dict[str, str | None]) -> None: """ Set the custom settings for the profile. This is also called when the settings are parsed from the config @@ -185,7 +185,7 @@ class Profile: def is_greeter_supported(self) -> bool: return self._support_greeter - def preview_text(self) -> str | None: + def preview_text(self) -> str: """ Override this method to provide a preview text for the profile """ diff --git a/archinstall/default_profiles/xorg.py b/archinstall/default_profiles/xorg.py index 4119f0bb..8745429f 100644 --- a/archinstall/default_profiles/xorg.py +++ b/archinstall/default_profiles/xorg.py @@ -27,7 +27,7 @@ class XorgProfile(Profile): ) @override - def preview_text(self) -> str | None: + def preview_text(self) -> str: text = str(_('Environment type: {}')).format(self.profile_type.value) if packages := self.packages_text(): text += f'\n{packages}' diff --git a/archinstall/lib/disk/device_model.py b/archinstall/lib/disk/device_model.py index a42834fa..35000290 100644 --- a/archinstall/lib/disk/device_model.py +++ b/archinstall/lib/disk/device_model.py @@ -5,7 +5,7 @@ import uuid from dataclasses import dataclass, field from enum import Enum from pathlib import Path -from typing import TYPE_CHECKING, Any, NotRequired, TypedDict +from typing import TYPE_CHECKING, NotRequired, TypedDict import parted from parted import Disk, Geometry, Partition @@ -422,7 +422,7 @@ class _PartitionInfo: sector_size = self.partition.geometry.device.sectorSize return SectorSize(sector_size, Unit.B) - def table_data(self) -> dict[str, Any]: + def table_data(self) -> dict[str, str]: end = self.start + self.length part_info = { @@ -496,7 +496,7 @@ class _DeviceInfo: read_only: bool dirty: bool - def table_data(self) -> dict[str, Any]: + def table_data(self) -> dict[str, str | int | bool]: total_free_space = sum([region.get_length(unit=Unit.MiB) for region in self.free_space_regions]) return { 'Model': self.model, @@ -601,7 +601,7 @@ class DeviceGeometry: def get_length(self, unit: Unit = Unit.sectors) -> int: return self._geometry.getLength(unit.name) - def table_data(self) -> dict[str, Any]: + def table_data(self) -> dict[str, str | int]: start = Size(self._geometry.start, Unit.sectors, self._sector_size) end = Size(self._geometry.end, Unit.sectors, self._sector_size) length = Size(self._geometry.getLength(), Unit.sectors, self._sector_size) @@ -946,7 +946,7 @@ class PartitionModification: 'btrfs': [vol.json() for vol in self.btrfs_subvols] } - def table_data(self) -> dict[str, Any]: + def table_data(self) -> dict[str, str]: """ Called for displaying data in table format """ @@ -958,7 +958,7 @@ class PartitionModification: 'End': self.end.format_size(Unit.sectors, self.start.sector_size, include_unit=False), 'Size': self.length.format_highest(), 'FS type': self.fs_type.value if self.fs_type else 'Unknown', - 'Mountpoint': self.mountpoint if self.mountpoint else '', + 'Mountpoint': str(self.mountpoint) if self.mountpoint else '', 'Mount options': ', '.join(self.mount_options), 'Flags': ', '.join([f.description for f in self.flags]), } @@ -1132,7 +1132,7 @@ class LvmVolume: 'btrfs': [vol.json() for vol in self.btrfs_subvols] } - def table_data(self) -> dict[str, Any]: + def table_data(self) -> dict[str, str]: part_mod = { 'Type': self.status.value, 'Name': self.name, diff --git a/archinstall/lib/locale/locale_menu.py b/archinstall/lib/locale/locale_menu.py index fa2b12ce..a92cd8c1 100644 --- a/archinstall/lib/locale/locale_menu.py +++ b/archinstall/lib/locale/locale_menu.py @@ -69,7 +69,7 @@ class LocaleMenu(AbstractSubMenu): locale_conf: LocaleConfiguration ): self._locale_conf = locale_conf - self._data_store: dict[str, Any] = {} + self._data_store: dict[str, str] = {} menu_optioons = self._define_menu_options() self._item_group = MenuItemGroup(menu_optioons, sort_items=False, checkmarks=True) diff --git a/archinstall/tui/curses_menu.py b/archinstall/tui/curses_menu.py index c99f1bcc..286c88d0 100644 --- a/archinstall/tui/curses_menu.py +++ b/archinstall/tui/curses_menu.py @@ -126,7 +126,7 @@ class AbstractViewport: def __init__(self) -> None: pass - def add_str(self, screen: Any, row: int, col: int, text: str, color: STYLE) -> None: + def add_str(self, screen: 'curses._CursesWindow', row: int, col: int, text: str, color: STYLE) -> None: try: screen.addstr(row, col, text, Tui.t().get_color(color)) except curses.error: @@ -1383,7 +1383,7 @@ class Tui: self.stop() @property - def screen(self) -> Any: + def screen(self) -> 'curses._CursesWindow': return self._screen @staticmethod diff --git a/pyproject.toml b/pyproject.toml index 089b429e..3f0fdd65 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,10 +90,6 @@ warn_unused_ignores = true module = "archinstall.default_profiles.*" disallow_any_explicit = true -[[tool.mypy.overrides]] -module = "archinstall.default_profiles.profile" -disallow_any_explicit = false - [[tool.mypy.overrides]] module = "archinstall.examples.*" disallow_any_explicit = true