Replace most Union[] instances with pipe syntax (#2843)
This commit is contained in:
parent
9626965982
commit
97d6d84c3c
|
|
@ -7,7 +7,7 @@ import curses
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Union, TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import archinstall
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ class DockerProfile(Profile):
|
|||
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]
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import pathlib
|
|||
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 @@ class UNSAFE_JSON(json.JSONEncoder, json.JSONDecoder):
|
|||
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 @@ class SysCommandWorker:
|
|||
# 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 @@ class SysCommandWorker:
|
|||
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 @@ class SysCommand:
|
|||
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,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import time
|
|||
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 @@ class Installer:
|
|||
# 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 @@ Exec = /bin/sh -c "{hook_command}"
|
|||
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 @@ Exec = /bin/sh -c "{hook_command}"
|
|||
# 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]
|
||||
|
||||
|
|
|
|||
|
|
@ -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 @@ class User:
|
|||
@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 = []
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import select
|
|||
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:
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from collections.abc import Callable
|
|||
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 @@ class FormattedOutput:
|
|||
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:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from pathlib import Path
|
|||
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 @@ class Pacman:
|
|||
)
|
||||
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]
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from functools import cached_property
|
|||
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 @@ class ProfileHandler:
|
|||
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 @@ class ProfileHandler:
|
|||
|
||||
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]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue