Start replacing Optional with union syntax (UP007 rule in Ruff) (#2836)

This commit is contained in:
correctmost 2024-11-16 17:02:08 -05:00 committed by GitHub
parent 58e4a94fdf
commit 8cda091e6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
25 changed files with 76 additions and 78 deletions

View File

@ -1,4 +1,4 @@
from typing import Any, TYPE_CHECKING, Optional
from typing import Any, TYPE_CHECKING
from archinstall.lib.output import info
from archinstall.lib.profile.profiles_handler import profile_handler
@ -40,7 +40,7 @@ class DesktopProfile(Profile):
]
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
combined_greeters: dict[GreeterType, int] = {}
for profile in self.current_selection:
if profile.default_greeter_type:
@ -56,7 +56,7 @@ class DesktopProfile(Profile):
for profile in self.current_selection:
profile.do_on_select()
def do_on_select(self) -> Optional[SelectResult]:
def do_on_select(self) -> SelectResult | None:
items = [
MenuItem(
p.name,

View File

@ -1,4 +1,4 @@
from typing import Optional, Any, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from archinstall.default_profiles.profile import ProfileType, GreeterType
from archinstall.default_profiles.xorg import XorgProfile
@ -23,5 +23,5 @@ class BspwmProfile(XorgProfile):
]
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
return GreeterType.Lightdm

View File

@ -1,4 +1,4 @@
from typing import Optional, Any, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from archinstall.default_profiles.profile import ProfileType, GreeterType
from archinstall.default_profiles.xorg import XorgProfile
@ -22,5 +22,5 @@ class BudgieProfile(XorgProfile):
]
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
return GreeterType.LightdmSlick

View File

@ -1,4 +1,4 @@
from typing import Optional, Any, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from archinstall.default_profiles.profile import ProfileType, GreeterType
from archinstall.default_profiles.xorg import XorgProfile
@ -28,5 +28,5 @@ class CinnamonProfile(XorgProfile):
]
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
return GreeterType.Lightdm

View File

@ -1,4 +1,4 @@
from typing import Optional, Any, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from archinstall.default_profiles.profile import ProfileType, GreeterType
from archinstall.default_profiles.xorg import XorgProfile
@ -18,5 +18,5 @@ class CosmicProfile(XorgProfile):
]
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
return GreeterType.CosmicSession

View File

@ -1,4 +1,4 @@
from typing import Optional, Any, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from archinstall.default_profiles.profile import ProfileType, GreeterType
from archinstall.default_profiles.xorg import XorgProfile
@ -20,7 +20,7 @@ class CutefishProfile(XorgProfile):
]
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
return GreeterType.Sddm
def install(self, install_session: 'Installer') -> None:

View File

@ -1,4 +1,4 @@
from typing import Optional, Any, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from archinstall.default_profiles.profile import ProfileType, GreeterType
from archinstall.default_profiles.xorg import XorgProfile
@ -20,5 +20,5 @@ class DeepinProfile(XorgProfile):
]
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
return GreeterType.Lightdm

View File

@ -1,4 +1,4 @@
from typing import Optional, Any, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from archinstall.default_profiles.profile import ProfileType, GreeterType
from archinstall.default_profiles.xorg import XorgProfile
@ -19,5 +19,5 @@ class EnlighenmentProfile(XorgProfile):
]
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
return GreeterType.Lightdm

View File

@ -1,4 +1,4 @@
from typing import Optional, Any, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from archinstall.default_profiles.profile import ProfileType, GreeterType
from archinstall.default_profiles.xorg import XorgProfile
@ -19,5 +19,5 @@ class GnomeProfile(XorgProfile):
]
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
return GreeterType.Gdm

View File

@ -1,5 +1,5 @@
from enum import Enum
from typing import Optional, TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any
from archinstall.default_profiles.profile import ProfileType, GreeterType, SelectResult
from archinstall.default_profiles.xorg import XorgProfile
@ -41,7 +41,7 @@ class HyprlandProfile(XorgProfile):
]
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
return GreeterType.Sddm
@property
@ -73,7 +73,7 @@ class HyprlandProfile(XorgProfile):
if result.item() is not None:
self.custom_settings['seat_access'] = result.get_value()
def do_on_select(self) -> Optional[SelectResult]:
def do_on_select(self) -> SelectResult | None:
self._ask_seat_access()
return None

View File

@ -1,4 +1,4 @@
from typing import Optional, Any, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from archinstall.default_profiles.profile import ProfileType, GreeterType
from archinstall.default_profiles.xorg import XorgProfile
@ -26,5 +26,5 @@ class I3wmProfile(XorgProfile):
]
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
return GreeterType.Lightdm

View File

@ -1,4 +1,4 @@
from typing import Optional, Any, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from archinstall.default_profiles.profile import ProfileType, GreeterType
from archinstall.default_profiles.xorg import XorgProfile
@ -27,5 +27,5 @@ class LxqtProfile(XorgProfile):
]
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
return GreeterType.Sddm

View File

@ -1,4 +1,4 @@
from typing import Optional, Any, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from archinstall.default_profiles.profile import ProfileType, GreeterType
from archinstall.default_profiles.xorg import XorgProfile
@ -19,5 +19,5 @@ class MateProfile(XorgProfile):
]
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
return GreeterType.Lightdm

View File

@ -1,4 +1,4 @@
from typing import Optional, Any, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from archinstall.default_profiles.profile import ProfileType, GreeterType
from archinstall.default_profiles.xorg import XorgProfile
@ -24,5 +24,5 @@ class PlasmaProfile(XorgProfile):
]
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
return GreeterType.Sddm

View File

@ -1,4 +1,4 @@
from typing import Optional, Any, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from archinstall.default_profiles.profile import ProfileType, GreeterType
from archinstall.default_profiles.xorg import XorgProfile
@ -19,5 +19,5 @@ class QtileProfile(XorgProfile):
]
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
return GreeterType.Lightdm

View File

@ -1,5 +1,5 @@
from enum import Enum
from typing import Optional, TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any
from archinstall.default_profiles.profile import ProfileType, GreeterType, SelectResult
from archinstall.default_profiles.xorg import XorgProfile
@ -51,7 +51,7 @@ class SwayProfile(XorgProfile):
] + additional
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
return GreeterType.Lightdm
@property
@ -83,7 +83,7 @@ class SwayProfile(XorgProfile):
if result.item() is not None:
self.custom_settings['seat_access'] = result.get_value()
def do_on_select(self) -> Optional[SelectResult]:
def do_on_select(self) -> SelectResult | None:
self._ask_seat_access()
return None

View File

@ -1,4 +1,4 @@
from typing import Optional, Any, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from archinstall.default_profiles.profile import ProfileType, GreeterType
from archinstall.default_profiles.xorg import XorgProfile
@ -22,5 +22,5 @@ class Xfce4Profile(XorgProfile):
]
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
return GreeterType.Lightdm

View File

@ -2,7 +2,7 @@ from __future__ import annotations
import sys
from enum import Enum, auto
from typing import Optional, Any, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from ..lib.storage import storage
@ -68,7 +68,7 @@ class Profile:
self._support_gfx_driver = support_gfx_driver
self._support_greeter = support_greeter
# self.gfx_driver: Optional[str] = None
# self.gfx_driver: str | None = None
self.current_selection = current_selection
self._packages = packages
@ -94,7 +94,7 @@ class Profile:
return self._services
@property
def default_greeter_type(self) -> Optional[GreeterType]:
def default_greeter_type(self) -> GreeterType | None:
"""
Setting a default greeter type for a desktop profile
"""
@ -125,7 +125,7 @@ class Profile:
"""
return {}
def do_on_select(self) -> Optional[SelectResult]:
def do_on_select(self) -> SelectResult | None:
"""
Hook that will be called when a profile is selected
"""
@ -180,7 +180,7 @@ class Profile:
def is_greeter_supported(self) -> bool:
return self._support_greeter
def preview_text(self) -> Optional[str]:
def preview_text(self) -> str | None:
"""
Override this method to provide a preview text for the profile
"""

View File

@ -1,4 +1,4 @@
from typing import Any, TYPE_CHECKING, Optional
from typing import Any, TYPE_CHECKING
from archinstall.lib.output import info
from archinstall.lib.profile.profiles_handler import profile_handler
@ -23,7 +23,7 @@ class ServerProfile(Profile):
current_selection=current_value
)
def do_on_select(self) -> Optional[SelectResult]:
def do_on_select(self) -> SelectResult | None:
items = [
MenuItem(
p.name,

View File

@ -1,4 +1,4 @@
from typing import Any, Optional, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from archinstall.default_profiles.profile import Profile, ProfileType
@ -22,7 +22,7 @@ class XorgProfile(Profile):
advanced=advanced
)
def preview_text(self) -> Optional[str]:
def preview_text(self) -> str | None:
text = str(_('Environment type: {}')).format(self.profile_type.value)
if packages := self.packages_text():
text += f'\n{packages}'

View File

@ -1,6 +1,5 @@
import time
from collections.abc import Iterator
from typing import Optional
from .exceptions import SysCallError
from .general import SysCommand, SysCommandWorker, locate_binary
from .installer import Installer
@ -12,7 +11,7 @@ class Boot:
def __init__(self, installation: Installer):
self.instance = installation
self.container_name = 'archinstall'
self.session: Optional[SysCommandWorker] = None
self.session: SysCommandWorker | None = None
self.ready = False
def __enter__(self) -> 'Boot':
@ -54,7 +53,7 @@ class Boot:
)
shutdown = None
shutdown_exit_code: Optional[int] = -1
shutdown_exit_code: int | None = -1
try:
shutdown = SysCommand(f'systemd-run --machine={self.container_name} --pty shutdown now')

View File

@ -8,7 +8,7 @@ import time
from collections.abc import Callable
from pathlib import Path
from types import TracebackType
from typing import Any, Optional, TYPE_CHECKING, Union
from typing import Any, TYPE_CHECKING, Union
from . import disk
from .exceptions import DiskError, ServiceException, RequirementError, HardwareIncompatibilityError, SysCallError
@ -47,9 +47,9 @@ class Installer:
self,
target: Path,
disk_config: disk.DiskLayoutConfiguration,
disk_encryption: Optional[disk.DiskEncryption] = None,
disk_encryption: disk.DiskEncryption | None = None,
base_packages: list[str] = [],
kernels: Optional[list[str]] = None
kernels: list[str] | None = None
):
"""
`Installer()` is the wrapper for most basic installation steps.
@ -628,7 +628,7 @@ class Installer:
def run_command(self, cmd: str, *args: str, **kwargs: str) -> SysCommand:
return SysCommand(f'/usr/bin/arch-chroot {self.target} {cmd}')
def arch_chroot(self, cmd: str, run_as: Optional[str] = None) -> SysCommand:
def arch_chroot(self, cmd: str, run_as: str | None = None) -> SysCommand:
if run_as:
cmd = f"su - {run_as} -c {shlex.quote(cmd)}"
@ -736,7 +736,7 @@ class Installer:
log(error.worker._trace_log.decode())
return False
def _get_microcode(self) -> Optional[Path]:
def _get_microcode(self) -> Path | None:
if not SysInfo.is_vm():
if vendor := SysInfo.cpu_vendor():
return vendor.get_ucode()
@ -911,19 +911,19 @@ class Installer:
else:
raise ValueError("Archinstall currently only supports setting up swap on zram")
def _get_efi_partition(self) -> Optional[disk.PartitionModification]:
def _get_efi_partition(self) -> disk.PartitionModification | None:
for layout in self._disk_config.device_modifications:
if partition := layout.get_efi_partition():
return partition
return None
def _get_boot_partition(self) -> Optional[disk.PartitionModification]:
def _get_boot_partition(self) -> disk.PartitionModification | None:
for layout in self._disk_config.device_modifications:
if boot := layout.get_boot_partition():
return boot
return None
def _get_root(self) -> Optional[disk.PartitionModification | disk.LvmVolume]:
def _get_root(self) -> disk.PartitionModification | disk.LvmVolume | None:
if self._disk_config.lvm_config:
return self._disk_config.lvm_config.get_root_volume()
else:
@ -1054,7 +1054,7 @@ class Installer:
self,
boot_partition: disk.PartitionModification,
root: disk.PartitionModification | disk.LvmVolume,
efi_partition: Optional[disk.PartitionModification],
efi_partition: disk.PartitionModification | None,
uki_enabled: bool = False
) -> None:
debug('Installing systemd bootloader')
@ -1153,7 +1153,7 @@ class Installer:
self,
boot_partition: disk.PartitionModification,
root: disk.PartitionModification | disk.LvmVolume,
efi_partition: Optional[disk.PartitionModification]
efi_partition: disk.PartitionModification | None
) -> None:
debug('Installing grub bootloader')
@ -1237,7 +1237,7 @@ class Installer:
def _add_limine_bootloader(
self,
boot_partition: disk.PartitionModification,
efi_partition: Optional[disk.PartitionModification],
efi_partition: disk.PartitionModification | None,
root: disk.PartitionModification | disk.LvmVolume
) -> None:
debug('Installing limine bootloader')
@ -1381,7 +1381,7 @@ Exec = /bin/sh -c "{hook_command}"
def _config_uki(
self,
root: disk.PartitionModification | disk.LvmVolume,
efi_partition: Optional[disk.PartitionModification]
efi_partition: disk.PartitionModification | None
) -> None:
if not efi_partition or not efi_partition.mountpoint:
raise ValueError(f'Could not detect ESP at mountpoint {self.target}')
@ -1512,7 +1512,7 @@ Exec = /bin/sh -c "{hook_command}"
for user in users:
self.user_create(user.username, user.password, user.groups, user.sudo)
def user_create(self, user: str, password: Optional[str] = None, groups: Optional[list[str]] = None, sudo: bool = False) -> None:
def user_create(self, user: str, password: str | None = None, groups: list[str] | None = None, sudo: bool = False) -> None:
if groups is None:
groups = []
@ -1630,7 +1630,7 @@ Exec = /bin/sh -c "{hook_command}"
return True
def _service_started(self, service_name: str) -> Optional[str]:
def _service_started(self, service_name: str) -> str | None:
if os.path.splitext(service_name)[1] not in ('.service', '.target', '.timer'):
service_name += '.service' # Just to be safe

View File

@ -1,5 +1,5 @@
from pathlib import Path
from typing import Any, TYPE_CHECKING, Optional
from typing import Any, TYPE_CHECKING
from ..output import FormattedOutput
from ..general import secret
@ -14,11 +14,11 @@ if TYPE_CHECKING:
def get_password(
text: str,
header: Optional[str] = None,
header: str | None = None,
allow_skip: bool = False,
preset: Optional[str] = None
) -> Optional[str]:
failure: Optional[str] = None
preset: str | None = None
) -> str | None:
failure: str | None = None
while True:
user_hdr = None
@ -63,12 +63,12 @@ def get_password(
def prompt_dir(
text: str,
header: Optional[str] = None,
header: str | None = None,
validate: bool = True,
allow_skip: bool = False,
preset: Optional[str] = None
) -> Optional[Path]:
def validate_path(path: str) -> Optional[str]:
preset: str | None = None
) -> Path | None:
def validate_path(path: str) -> str | None:
dest_path = Path(path)
if dest_path.exists() and dest_path.is_dir():
@ -107,7 +107,7 @@ def is_subpath(first: Path, second: Path) -> bool:
return False
def format_cols(items: list[str], header: Optional[str] = None) -> str:
def format_cols(items: list[str], header: str | None = None) -> str:
if header:
text = f'{header}:\n'
else:

View File

@ -806,8 +806,8 @@ class SelectMenu(AbstractCurses):
alignment: Alignment = Alignment.LEFT,
columns: int = 1,
column_spacing: int = 10,
header: Optional[str] = None,
frame: Optional[FrameProperties] = None,
header: str | None = None,
frame: FrameProperties | None = None,
cursor_char: str = '>',
search_enabled: bool = True,
allow_skip: bool = False,

View File

@ -1,5 +1,4 @@
from pathlib import Path
from typing import Optional
import archinstall
from archinstall import info, debug
@ -97,7 +96,7 @@ def perform_installation(mountpoint: Path) -> None:
# If user selected to copy the current ISO network configuration
# Perform a copy of the config
network_config: Optional[NetworkConfiguration] = archinstall.arguments.get('network_config', None)
network_config: NetworkConfiguration | None = archinstall.arguments.get('network_config', None)
if network_config:
network_config.install_network_config(
@ -108,7 +107,7 @@ def perform_installation(mountpoint: Path) -> None:
if users := archinstall.arguments.get('!users', None):
installation.create_users(users)
audio_config: Optional[AudioConfiguration] = archinstall.arguments.get('audio_config', None)
audio_config: AudioConfiguration | None = archinstall.arguments.get('audio_config', None)
if audio_config:
audio_config.install_audio_config(installation)
else: