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
|
import traceback
|
||||||
from argparse import ArgumentParser, Namespace
|
from argparse import ArgumentParser, Namespace
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING, Any, Union
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from .lib import disk
|
from .lib import disk
|
||||||
from .lib import models
|
from .lib import models
|
||||||
|
|
@ -150,7 +150,7 @@ def parse_unspecified_argument_list(unknowns: list, multiple: bool = False, err:
|
||||||
return config
|
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
|
Takes arguments (dictionary or argparse Namespace) and removes any
|
||||||
None values. This ensures clean mergers during dict.update(args)
|
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
|
import archinstall
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ class DockerProfile(Profile):
|
||||||
return ['docker']
|
return ['docker']
|
||||||
|
|
||||||
def post_install(self, install_session: 'Installer') -> None:
|
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):
|
if not isinstance(users, list):
|
||||||
users = [users]
|
users = [users]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import pathlib
|
||||||
from collections.abc import Callable, Iterator
|
from collections.abc import Callable, Iterator
|
||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, Union, TYPE_CHECKING
|
from typing import Any, TYPE_CHECKING
|
||||||
from select import epoll, EPOLLIN, EPOLLHUP
|
from select import epoll, EPOLLIN, EPOLLHUP
|
||||||
from shutil import which
|
from shutil import which
|
||||||
|
|
||||||
|
|
@ -41,7 +41,7 @@ def locate_binary(name: str) -> str:
|
||||||
raise RequirementError(f"Binary {name} does not exist.")
|
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
|
# https://stackoverflow.com/a/43627833/929999
|
||||||
vt100_escape_regex = r'\x1B\[[?0-9;]*[a-zA-Z]'
|
vt100_escape_regex = r'\x1B\[[?0-9;]*[a-zA-Z]'
|
||||||
if isinstance(data, bytes):
|
if isinstance(data, bytes):
|
||||||
|
|
@ -103,7 +103,7 @@ class UNSAFE_JSON(json.JSONEncoder, json.JSONDecoder):
|
||||||
class SysCommandWorker:
|
class SysCommandWorker:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
cmd: Union[str, list[str]],
|
cmd: str | list[str],
|
||||||
callbacks: dict[str, Any] | None = None,
|
callbacks: dict[str, Any] | None = None,
|
||||||
peek_output: bool | None = False,
|
peek_output: bool | None = False,
|
||||||
environment_vars: dict[str, Any] | None = None,
|
environment_vars: dict[str, Any] | None = None,
|
||||||
|
|
@ -235,7 +235,7 @@ class SysCommandWorker:
|
||||||
# Safety check to ensure 0 < pos < len(tracelog)
|
# Safety check to ensure 0 < pos < len(tracelog)
|
||||||
self._trace_log_pos = min(max(0, pos), len(self._trace_log))
|
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 self.peek_output:
|
||||||
if isinstance(output, bytes):
|
if isinstance(output, bytes):
|
||||||
try:
|
try:
|
||||||
|
|
@ -347,7 +347,7 @@ class SysCommandWorker:
|
||||||
class SysCommand:
|
class SysCommand:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
cmd: Union[str, list[str]],
|
cmd: str | list[str],
|
||||||
callbacks: dict[str, Callable[[Any], Any]] = {},
|
callbacks: dict[str, Callable[[Any], Any]] = {},
|
||||||
start_callback: Callable[[Any], Any] | None = None,
|
start_callback: Callable[[Any], Any] | None = None,
|
||||||
peek_output: bool | None = False,
|
peek_output: bool | None = False,
|
||||||
|
|
@ -397,7 +397,7 @@ class SysCommand:
|
||||||
def __repr__(self, *args: list[Any], **kwargs: dict[str, Any]) -> str:
|
def __repr__(self, *args: list[Any], **kwargs: dict[str, Any]) -> str:
|
||||||
return self.decode('UTF-8', errors='backslashreplace') or ''
|
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 {
|
return {
|
||||||
'cmd': self.cmd,
|
'cmd': self.cmd,
|
||||||
'callbacks': self._callbacks,
|
'callbacks': self._callbacks,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import time
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from types import TracebackType
|
from types import TracebackType
|
||||||
from typing import Any, TYPE_CHECKING, Union
|
from typing import Any, TYPE_CHECKING
|
||||||
|
|
||||||
from . import disk
|
from . import disk
|
||||||
from .exceptions import DiskError, ServiceException, RequirementError, HardwareIncompatibilityError, SysCallError
|
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.
|
# fstrim is owned by util-linux, a dependency of both base and systemd.
|
||||||
self.enable_service("fstrim.timer")
|
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):
|
if isinstance(services, str):
|
||||||
services = [services]
|
services = [services]
|
||||||
|
|
||||||
|
|
@ -1473,7 +1473,7 @@ Exec = /bin/sh -c "{hook_command}"
|
||||||
case Bootloader.Limine:
|
case Bootloader.Limine:
|
||||||
self._add_limine_bootloader(boot_partition, efi_partition, root)
|
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)
|
return self.pacman.strap(packages)
|
||||||
|
|
||||||
def enable_sudo(self, entity: str, group: bool = False):
|
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
|
# Guarantees sudoer conf file recommended perms
|
||||||
os.chmod(Path(rule_file_name), 0o440)
|
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):
|
if not isinstance(users, list):
|
||||||
users = [users]
|
users = [users]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Union, Any, TYPE_CHECKING
|
from typing import Any, TYPE_CHECKING
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
|
@ -148,8 +148,8 @@ class User:
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_arguments(
|
def parse_arguments(
|
||||||
cls,
|
cls,
|
||||||
config_users: Union[list[dict[str, str]], dict[str, str]],
|
config_users: list[dict[str, str]] | dict[str, str],
|
||||||
config_superusers: Union[list[dict[str, str]], dict[str, str]]
|
config_superusers: list[dict[str, str]] | dict[str, str]
|
||||||
) -> list['User']:
|
) -> list['User']:
|
||||||
users = []
|
users = []
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import select
|
||||||
import signal
|
import signal
|
||||||
import random
|
import random
|
||||||
from types import FrameType
|
from types import FrameType
|
||||||
from typing import Union, Any
|
from typing import Any
|
||||||
from urllib.error import URLError
|
from urllib.error import URLError
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
|
@ -100,7 +100,7 @@ def update_keyring() -> bool:
|
||||||
return False
|
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 = {}
|
result = {}
|
||||||
|
|
||||||
for iface in interfaces:
|
for iface in interfaces:
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ from collections.abc import Callable
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Union, Any, TYPE_CHECKING
|
from typing import Any, TYPE_CHECKING
|
||||||
from dataclasses import asdict, is_dataclass
|
from dataclasses import asdict, is_dataclass
|
||||||
|
|
||||||
from .storage import storage
|
from .storage import storage
|
||||||
|
|
@ -21,7 +21,7 @@ class FormattedOutput:
|
||||||
def _get_values(
|
def _get_values(
|
||||||
cls,
|
cls,
|
||||||
o: 'DataclassInstance',
|
o: 'DataclassInstance',
|
||||||
class_formatter: Union[str, Callable] | None = None,
|
class_formatter: str | Callable | None = None,
|
||||||
filter_list: list[str] = []
|
filter_list: list[str] = []
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
|
|
@ -53,7 +53,7 @@ class FormattedOutput:
|
||||||
def as_table(
|
def as_table(
|
||||||
cls,
|
cls,
|
||||||
obj: list[Any],
|
obj: list[Any],
|
||||||
class_formatter: Union[str, Callable] | None = None,
|
class_formatter: str | Callable | None = None,
|
||||||
filter_list: list[str] = [],
|
filter_list: list[str] = [],
|
||||||
capitalize: bool = False
|
capitalize: bool = False
|
||||||
) -> str:
|
) -> str:
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ from pathlib import Path
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from typing import TYPE_CHECKING, Any, Union
|
from typing import TYPE_CHECKING, Any
|
||||||
from shutil import copy2
|
from shutil import copy2
|
||||||
|
|
||||||
from ..general import SysCommand
|
from ..general import SysCommand
|
||||||
|
|
@ -68,7 +68,7 @@ class Pacman:
|
||||||
)
|
)
|
||||||
self.synced = True
|
self.synced = True
|
||||||
|
|
||||||
def strap(self, packages: Union[str, list[str]]) -> None:
|
def strap(self, packages: str | list[str]) -> None:
|
||||||
self.sync()
|
self.sync()
|
||||||
if isinstance(packages, str):
|
if isinstance(packages, str):
|
||||||
packages = [packages]
|
packages = [packages]
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ from functools import cached_property
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
from types import ModuleType
|
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 ...default_profiles.profile import Profile, GreeterType
|
||||||
from .profile_model import ProfileConfiguration
|
from .profile_model import ProfileConfiguration
|
||||||
|
|
@ -138,7 +138,7 @@ class ProfileHandler:
|
||||||
def _local_mac_addresses(self) -> list[str]:
|
def _local_mac_addresses(self) -> list[str]:
|
||||||
return list(list_interfaces())
|
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):
|
if not isinstance(profiles, list):
|
||||||
profiles = [profiles]
|
profiles = [profiles]
|
||||||
|
|
||||||
|
|
@ -147,7 +147,7 @@ class ProfileHandler:
|
||||||
|
|
||||||
self._verify_unique_profile_names(self.profiles)
|
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):
|
if not isinstance(profiles, list):
|
||||||
profiles = [profiles]
|
profiles = [profiles]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue