Skip to content

Commit

Permalink
Replace most Union[] instances with pipe syntax (archlinux#2843)
Browse files Browse the repository at this point in the history
  • Loading branch information
correctmost authored Nov 18, 2024
1 parent 9626965 commit 97d6d84
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions archinstall/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions archinstall/default_profiles/servers/docker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union, TYPE_CHECKING
from typing import TYPE_CHECKING

import archinstall

Expand All @@ -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]

Expand Down
12 changes: 6 additions & 6 deletions archinstall/lib/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions archinstall/lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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]

Expand Down
6 changes: 3 additions & 3 deletions archinstall/lib/models/users.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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 = []

Expand Down
4 changes: 2 additions & 2 deletions archinstall/lib/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions archinstall/lib/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]:
"""
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions archinstall/lib/pacman/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions archinstall/lib/profile/profiles_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]

Expand All @@ -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]

Expand Down

0 comments on commit 97d6d84

Please sign in to comment.