diff --git a/archinstall/__init__.py b/archinstall/__init__.py index 086991b2d6..e1b7147d84 100644 --- a/archinstall/__init__.py +++ b/archinstall/__init__.py @@ -7,7 +7,7 @@ import traceback from argparse import ArgumentParser, Namespace from pathlib import Path -from typing import TYPE_CHECKING, Any, Union +from typing import TYPE_CHECKING, Any from .lib import disk from .lib import models @@ -150,7 +150,7 @@ def parse_unspecified_argument_list(unknowns: list, multiple: bool = False, err: return config -def cleanup_empty_args(args: Union[Namespace, dict]) -> dict: # type: ignore[type-arg] +def cleanup_empty_args(args: Namespace | dict) -> dict: # type: ignore[type-arg] """ Takes arguments (dictionary or argparse Namespace) and removes any None values. This ensures clean mergers during dict.update(args) diff --git a/archinstall/default_profiles/servers/docker.py b/archinstall/default_profiles/servers/docker.py index 62d3b9ee2e..901d8466fc 100644 --- a/archinstall/default_profiles/servers/docker.py +++ b/archinstall/default_profiles/servers/docker.py @@ -1,4 +1,4 @@ -from typing import Union, TYPE_CHECKING +from typing import TYPE_CHECKING import archinstall @@ -25,7 +25,7 @@ def services(self) -> list[str]: return ['docker'] def post_install(self, install_session: 'Installer') -> None: - users: Union[User, list[User]] = archinstall.arguments.get('!users', []) + users: User | list[User] = archinstall.arguments.get('!users', []) if not isinstance(users, list): users = [users] diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py index b4dec50320..80ca839282 100644 --- a/archinstall/lib/general.py +++ b/archinstall/lib/general.py @@ -17,7 +17,7 @@ from collections.abc import Callable, Iterator from datetime import datetime, date from enum import Enum -from typing import Any, Union, TYPE_CHECKING +from typing import Any, TYPE_CHECKING from select import epoll, EPOLLIN, EPOLLHUP from shutil import which @@ -41,7 +41,7 @@ def locate_binary(name: str) -> str: raise RequirementError(f"Binary {name} does not exist.") -def clear_vt100_escape_codes(data: Union[bytes, str]) -> Union[bytes, str]: +def clear_vt100_escape_codes(data: bytes | str) -> bytes | str: # https://stackoverflow.com/a/43627833/929999 vt100_escape_regex = r'\x1B\[[?0-9;]*[a-zA-Z]' if isinstance(data, bytes): @@ -103,7 +103,7 @@ def encode(self, o: Any) -> str: class SysCommandWorker: def __init__( self, - cmd: Union[str, list[str]], + cmd: str | list[str], callbacks: dict[str, Any] | None = None, peek_output: bool | None = False, environment_vars: dict[str, Any] | None = None, @@ -235,7 +235,7 @@ def seek(self, pos: int) -> None: # Safety check to ensure 0 < pos < len(tracelog) self._trace_log_pos = min(max(0, pos), len(self._trace_log)) - def peak(self, output: Union[str, bytes]) -> bool: + def peak(self, output: str | bytes) -> bool: if self.peek_output: if isinstance(output, bytes): try: @@ -347,7 +347,7 @@ def decode(self, encoding: str = 'UTF-8') -> str: class SysCommand: def __init__( self, - cmd: Union[str, list[str]], + cmd: str | list[str], callbacks: dict[str, Callable[[Any], Any]] = {}, start_callback: Callable[[Any], Any] | None = None, peek_output: bool | None = False, @@ -397,7 +397,7 @@ def __getitem__(self, key: slice) -> bytes | None: def __repr__(self, *args: list[Any], **kwargs: dict[str, Any]) -> str: return self.decode('UTF-8', errors='backslashreplace') or '' - def __json__(self) -> dict[str, Union[str, bool, list[str], dict[str, Any], bool | None, dict[str, Any] | None]]: + def __json__(self) -> dict[str, str | bool | list[str] | dict[str, Any] | None]: return { 'cmd': self.cmd, 'callbacks': self._callbacks, diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 3f7793ea44..3079f41699 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -8,7 +8,7 @@ from collections.abc import Callable from pathlib import Path from types import TracebackType -from typing import Any, TYPE_CHECKING, Union +from typing import Any, TYPE_CHECKING from . import disk from .exceptions import DiskError, ServiceException, RequirementError, HardwareIncompatibilityError, SysCallError @@ -610,7 +610,7 @@ def enable_periodic_trim(self) -> None: # fstrim is owned by util-linux, a dependency of both base and systemd. self.enable_service("fstrim.timer") - def enable_service(self, services: Union[str, list[str]]) -> None: + def enable_service(self, services: str | list[str]) -> None: if isinstance(services, str): services = [services] @@ -1473,7 +1473,7 @@ def add_bootloader(self, bootloader: Bootloader, uki_enabled: bool = False): case Bootloader.Limine: self._add_limine_bootloader(boot_partition, efi_partition, root) - def add_additional_packages(self, packages: Union[str, list[str]]) -> None: + def add_additional_packages(self, packages: str | list[str]) -> None: return self.pacman.strap(packages) def enable_sudo(self, entity: str, group: bool = False): @@ -1506,7 +1506,7 @@ def enable_sudo(self, entity: str, group: bool = False): # Guarantees sudoer conf file recommended perms os.chmod(Path(rule_file_name), 0o440) - def create_users(self, users: Union[User, list[User]]) -> None: + def create_users(self, users: User | list[User]) -> None: if not isinstance(users, list): users = [users] diff --git a/archinstall/lib/models/users.py b/archinstall/lib/models/users.py index 922b886d90..b74f815069 100644 --- a/archinstall/lib/models/users.py +++ b/archinstall/lib/models/users.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from typing import Union, Any, TYPE_CHECKING +from typing import Any, TYPE_CHECKING from enum import Enum if TYPE_CHECKING: @@ -148,8 +148,8 @@ def _parse_backwards_compatible(cls, config_users: dict, sudo: bool) -> list['Us @classmethod def parse_arguments( cls, - config_users: Union[list[dict[str, str]], dict[str, str]], - config_superusers: Union[list[dict[str, str]], dict[str, str]] + config_users: list[dict[str, str]] | dict[str, str], + config_superusers: list[dict[str, str]] | dict[str, str] ) -> list['User']: users = [] diff --git a/archinstall/lib/networking.py b/archinstall/lib/networking.py index f7a7de0513..43e76cf79f 100644 --- a/archinstall/lib/networking.py +++ b/archinstall/lib/networking.py @@ -7,7 +7,7 @@ import signal import random from types import FrameType -from typing import Union, Any +from typing import Any from urllib.error import URLError from urllib.parse import urlencode from urllib.request import urlopen @@ -100,7 +100,7 @@ def update_keyring() -> bool: return False -def enrich_iface_types(interfaces: Union[dict[str, Any], list[str]]) -> dict[str, str]: +def enrich_iface_types(interfaces: dict[str, Any] | list[str]) -> dict[str, str]: result = {} for iface in interfaces: diff --git a/archinstall/lib/output.py b/archinstall/lib/output.py index 290cb8fe57..f281cabf5a 100644 --- a/archinstall/lib/output.py +++ b/archinstall/lib/output.py @@ -6,7 +6,7 @@ from enum import Enum from pathlib import Path -from typing import Union, Any, TYPE_CHECKING +from typing import Any, TYPE_CHECKING from dataclasses import asdict, is_dataclass from .storage import storage @@ -21,7 +21,7 @@ class FormattedOutput: def _get_values( cls, o: 'DataclassInstance', - class_formatter: Union[str, Callable] | None = None, + class_formatter: str | Callable | None = None, filter_list: list[str] = [] ) -> dict[str, Any]: """ @@ -53,7 +53,7 @@ def _get_values( def as_table( cls, obj: list[Any], - class_formatter: Union[str, Callable] | None = None, + class_formatter: str | Callable | None = None, filter_list: list[str] = [], capitalize: bool = False ) -> str: diff --git a/archinstall/lib/pacman/__init__.py b/archinstall/lib/pacman/__init__.py index 032d39d815..4d84e2cfd9 100644 --- a/archinstall/lib/pacman/__init__.py +++ b/archinstall/lib/pacman/__init__.py @@ -2,7 +2,7 @@ import time import re from collections.abc import Callable -from typing import TYPE_CHECKING, Any, Union +from typing import TYPE_CHECKING, Any from shutil import copy2 from ..general import SysCommand @@ -68,7 +68,7 @@ def sync(self) -> None: ) self.synced = True - def strap(self, packages: Union[str, list[str]]) -> None: + def strap(self, packages: str | list[str]) -> None: self.sync() if isinstance(packages, str): packages = [packages] diff --git a/archinstall/lib/profile/profiles_handler.py b/archinstall/lib/profile/profiles_handler.py index 43d34d53e8..3cf8a7e8bf 100644 --- a/archinstall/lib/profile/profiles_handler.py +++ b/archinstall/lib/profile/profiles_handler.py @@ -8,7 +8,7 @@ from pathlib import Path from tempfile import NamedTemporaryFile from types import ModuleType -from typing import TYPE_CHECKING, Any, Union +from typing import TYPE_CHECKING, Any from ...default_profiles.profile import Profile, GreeterType from .profile_model import ProfileConfiguration @@ -138,7 +138,7 @@ def profiles(self) -> list[Profile]: def _local_mac_addresses(self) -> list[str]: return list(list_interfaces()) - def add_custom_profiles(self, profiles: Union[Profile, list[Profile]]) -> None: + def add_custom_profiles(self, profiles: Profile | list[Profile]) -> None: if not isinstance(profiles, list): profiles = [profiles] @@ -147,7 +147,7 @@ def add_custom_profiles(self, profiles: Union[Profile, list[Profile]]) -> None: self._verify_unique_profile_names(self.profiles) - def remove_custom_profiles(self, profiles: Union[Profile, list[Profile]]) -> None: + def remove_custom_profiles(self, profiles: Profile | list[Profile]) -> None: if not isinstance(profiles, list): profiles = [profiles]