diff --git a/archinstall/default_profiles/desktop.py b/archinstall/default_profiles/desktop.py index f919535742..fc3b712c30 100644 --- a/archinstall/default_profiles/desktop.py +++ b/archinstall/default_profiles/desktop.py @@ -14,7 +14,7 @@ class DesktopProfile(Profile): - def __init__(self, current_selection: list[Self] = []) -> None: + def __init__(self, current_selection: list[Self] | None = None) -> None: super().__init__( 'Desktop', ProfileType.Desktop, diff --git a/archinstall/default_profiles/profile.py b/archinstall/default_profiles/profile.py index 248f83ba51..d473840ca2 100644 --- a/archinstall/default_profiles/profile.py +++ b/archinstall/default_profiles/profile.py @@ -56,9 +56,9 @@ def __init__( self, name: str, profile_type: ProfileType, - current_selection: list[Self] = [], - packages: list[str] = [], - services: list[str] = [], + current_selection: list[Self] | None = None, + packages: list[str] | None = None, + services: list[str] | None = None, support_gfx_driver: bool = False, support_greeter: bool = False, display_server: DisplayServerType | None = None, @@ -73,9 +73,12 @@ def __init__( # self.gfx_driver: str | None = None + if current_selection is None: + current_selection = [] + self.current_selection = current_selection - self._packages = packages - self._services = services + self._packages = packages if packages is not None else [] + self._services = services if services is not None else [] # Only used for custom default_profiles self.custom_enabled = False diff --git a/archinstall/default_profiles/server.py b/archinstall/default_profiles/server.py index 0e2506e02e..b407fbe317 100644 --- a/archinstall/default_profiles/server.py +++ b/archinstall/default_profiles/server.py @@ -13,7 +13,7 @@ class ServerProfile(Profile): - def __init__(self, current_value: list[Self] = []): + def __init__(self, current_value: list[Self] | None = None): super().__init__( 'Server', ProfileType.Server, diff --git a/archinstall/lib/disk/device_handler.py b/archinstall/lib/disk/device_handler.py index 4a1b2b2a12..8a6ce739b6 100644 --- a/archinstall/lib/disk/device_handler.py +++ b/archinstall/lib/disk/device_handler.py @@ -236,7 +236,7 @@ def format( self, fs_type: FilesystemType, path: Path, - additional_parted_options: list[str] = [], + additional_parted_options: list[str] | None = None, ) -> None: mkfs_type = fs_type.value command = None @@ -264,6 +264,9 @@ def format( if not command: command = f'mkfs.{mkfs_type}' + if additional_parted_options is None: + additional_parted_options = [] + cmd = [command, *options, *additional_parted_options, str(path)] debug('Formatting filesystem:', ' '.join(cmd)) diff --git a/archinstall/lib/disk/disk_menu.py b/archinstall/lib/disk/disk_menu.py index 54d0c8d9bd..497379d14c 100644 --- a/archinstall/lib/disk/disk_menu.py +++ b/archinstall/lib/disk/disk_menu.py @@ -297,7 +297,7 @@ def _prev_disk_encryption(self, item: MenuItem) -> str | None: return None -async def select_devices(preset: list[BDevice] | None = []) -> list[BDevice] | None: +async def select_devices(preset: list[BDevice] | None = None) -> list[BDevice] | None: def _preview_device_selection(item: MenuItem) -> str | None: device: _DeviceInfo = item.value # type: ignore[assignment] dev = device_handler.get_device(device.path) @@ -306,9 +306,6 @@ def _preview_device_selection(item: MenuItem) -> str | None: return as_table(dev.partition_infos) return None - if preset is None: - preset = [] - devices = device_handler.devices if len(devices) < 1: @@ -324,7 +321,10 @@ def _preview_device_selection(item: MenuItem) -> str | None: for d in devices ] - presets = [p.device_info for p in preset] + if preset is None: + presets = [] + else: + presets = [p.device_info for p in preset] group = MenuItemGroup(items) group.set_selected_by_value(presets) diff --git a/archinstall/lib/disk/filesystem.py b/archinstall/lib/disk/filesystem.py index 5fe2e11c5c..9f55b15be7 100644 --- a/archinstall/lib/disk/filesystem.py +++ b/archinstall/lib/disk/filesystem.py @@ -161,7 +161,7 @@ def _setup_lvm_encrypted(self, lvm_config: LvmConfiguration, enc_config: DiskEnc def _setup_lvm( self, lvm_config: LvmConfiguration, - enc_mods: dict[PartitionModification, Luks2] = {}, + enc_mods: dict[PartitionModification, Luks2] | None = None, ) -> None: self._lvm_create_pvs(lvm_config, enc_mods) @@ -216,10 +216,10 @@ def _setup_lvm( def _format_lvm_vols( self, lvm_config: LvmConfiguration, - enc_vols: dict[LvmVolume, Luks2] = {}, + enc_vols: dict[LvmVolume, Luks2] | None = None, ) -> None: for vol in lvm_config.get_all_volumes(): - if enc_vol := enc_vols.get(vol, None): + if enc_vols is not None and (enc_vol := enc_vols.get(vol, None)): if not enc_vol.mapper_dev: raise ValueError('No mapper device defined') path = enc_vol.mapper_dev @@ -236,7 +236,7 @@ def _format_lvm_vols( def _lvm_create_pvs( self, lvm_config: LvmConfiguration, - enc_mods: dict[PartitionModification, Luks2] = {}, + enc_mods: dict[PartitionModification, Luks2] | None = None, ) -> None: pv_paths: set[Path] = set() @@ -248,12 +248,12 @@ def _lvm_create_pvs( def _get_all_pv_dev_paths( self, pvs: list[PartitionModification], - enc_mods: dict[PartitionModification, Luks2] = {}, + enc_mods: dict[PartitionModification, Luks2] | None = None, ) -> set[Path]: pv_paths: set[Path] = set() for pv in pvs: - if enc_pv := enc_mods.get(pv, None): + if enc_mods is not None and (enc_pv := enc_mods.get(pv, None)): if mapper := enc_pv.mapper_dev: pv_paths.add(mapper) else: diff --git a/archinstall/lib/disk/utils.py b/archinstall/lib/disk/utils.py index 30bdfb9327..445dc69412 100644 --- a/archinstall/lib/disk/utils.py +++ b/archinstall/lib/disk/utils.py @@ -141,7 +141,7 @@ def mount( target_mountpoint: Path, mount_fs: str | None = None, create_target_mountpoint: bool = True, - options: list[str] = [], + options: list[str] | None = None, ) -> None: if create_target_mountpoint and not target_mountpoint.exists(): target_mountpoint.mkdir(parents=True, exist_ok=True) @@ -156,7 +156,7 @@ def mount( cmd = ['mount'] - if len(options): + if options: cmd.extend(('-o', ','.join(options))) if mount_fs: cmd.extend(('-t', mount_fs)) diff --git a/archinstall/lib/general/system_menu.py b/archinstall/lib/general/system_menu.py index d302a52fa8..d2de676fe1 100644 --- a/archinstall/lib/general/system_menu.py +++ b/archinstall/lib/general/system_menu.py @@ -9,13 +9,16 @@ from archinstall.tui.result import ResultType -async def select_kernel(preset: list[Kernel] = []) -> list[Kernel]: +async def select_kernel(preset: list[Kernel] | None = None) -> list[Kernel]: """ Asks the user to select a kernel for system. :return: The string as a selected kernel :rtype: string """ + if preset is None: + preset = [] + group = MenuItemGroup.from_enum(Kernel, sort_items=True, preset=preset) group.set_default_by_value(DEFAULT_KERNEL) group.set_focus_by_value(DEFAULT_KERNEL) @@ -51,7 +54,10 @@ async def select_uki(preset: bool = True) -> bool: raise ValueError('Unhandled result type') -async def select_driver(options: list[GfxDriver] = [], preset: GfxDriver | None = None) -> GfxDriver | None: +async def select_driver( + options: list[GfxDriver] | None = None, + preset: GfxDriver | None = None, +) -> GfxDriver | None: """ Somewhat convoluted function, whose job is simple. Select a graphics driver from a pre-defined set of popular options. diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index aeb5c6aea1..4267f9f0de 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -77,7 +77,7 @@ def __init__( self, target: Path, disk_config: DiskLayoutConfiguration, - base_packages: list[str] = [], + base_packages: list[str] | None = None, kernels: list[str] | None = None, silent: bool = False, ): @@ -312,7 +312,7 @@ def _mount_partition_layout(self, luks_handlers: dict[Any, Luks2]) -> None: else: self._mount_partition(part_mod) - def _mount_lvm_layout(self, luks_handlers: dict[Any, Luks2] = {}) -> None: + def _mount_lvm_layout(self, luks_handlers: dict[Any, Luks2] | None = None) -> None: lvm_config = self._disk_config.lvm_config if not lvm_config: @@ -325,7 +325,7 @@ def _mount_lvm_layout(self, luks_handlers: dict[Any, Luks2] = {}) -> None: sorted_vol = sorted(vg.volumes, key=lambda x: x.mountpoint or Path('/')) for vol in sorted_vol: - if luks_handler := luks_handlers.get(vol): + if luks_handlers is not None and (luks_handler := luks_handlers.get(vol)): self._mount_luks_volume(vol, luks_handler) else: self._mount_lvm_vol(vol) @@ -437,8 +437,11 @@ def _mount_btrfs_subvol( self, dev_path: Path, subvolumes: list[SubvolumeModification], - mount_options: list[str] = [], + mount_options: list[str] | None = None, ) -> None: + if mount_options is None: + mount_options = [] + # Filter out subvolumes without mountpoints to avoid errors when sorting subvols_with_mountpoints = [sv for sv in subvolumes if sv.mountpoint is not None] for subvol in sorted(subvols_with_mountpoints, key=lambda x: x.relative_mountpoint): @@ -897,7 +900,7 @@ def _prepare_encrypt(self, before: str = 'filesystems') -> None: def minimal_installation( self, - optional_repositories: list[Repository] = [], + optional_repositories: list[Repository] | None = None, mkinitcpio: bool = True, hostname: str | None = None, locale_config: LocaleConfiguration | None = LocaleConfiguration.default(), @@ -933,6 +936,9 @@ def minimal_installation( else: debug('Archinstall will not install any ucode.') + if optional_repositories is None: + optional_repositories = [] + debug(f'Optional repositories: {optional_repositories}') # This action takes place on the host system as pacstrap copies over package repository lists. diff --git a/archinstall/lib/log.py b/archinstall/lib/log.py index bd060e99f1..08e4844129 100644 --- a/archinstall/lib/log.py +++ b/archinstall/lib/log.py @@ -97,7 +97,7 @@ def _stylize_output( fg: str, bg: str | None, reset: bool, - font: list[Font] = [], + font: list[Font] | None = None, ) -> str: """ Heavily influenced by: @@ -137,8 +137,9 @@ def _stylize_output( if bg: code_list.append(background[str(bg)]) - for o in font: - code_list.append(o.value) + if font is not None: + for o in font: + code_list.append(o.value) ansi = ';'.join(code_list) @@ -167,7 +168,7 @@ def info( fg: str = 'white', bg: str | None = None, reset: bool = False, - font: list[Font] = [], + font: list[Font] | None = None, ) -> None: log(*msgs, level=level, fg=fg, bg=bg, reset=reset, font=font) @@ -178,7 +179,7 @@ def debug( fg: str = 'white', bg: str | None = None, reset: bool = False, - font: list[Font] = [], + font: list[Font] | None = None, ) -> None: log(*msgs, level=level, fg=fg, bg=bg, reset=reset, font=font) @@ -189,7 +190,7 @@ def error( fg: str = 'red', bg: str | None = None, reset: bool = False, - font: list[Font] = [], + font: list[Font] | None = None, ) -> None: log(*msgs, level=level, fg=fg, bg=bg, reset=reset, font=font) @@ -200,7 +201,7 @@ def warn( fg: str = 'yellow', bg: str | None = None, reset: bool = False, - font: list[Font] = [], + font: list[Font] | None = None, ) -> None: log(*msgs, level=level, fg=fg, bg=bg, reset=reset, font=font) @@ -211,7 +212,7 @@ def log( fg: str = 'white', bg: str | None = None, reset: bool = False, - font: list[Font] = [], + font: list[Font] | None = None, ) -> None: text = ' '.join(str(x) for x in msgs) diff --git a/archinstall/lib/menu/menu_helper.py b/archinstall/lib/menu/menu_helper.py index 0d9a4032bb..e5e00fc94b 100644 --- a/archinstall/lib/menu/menu_helper.py +++ b/archinstall/lib/menu/menu_helper.py @@ -6,8 +6,11 @@ class MenuHelper[ValueT]: def __init__( self, data: list[ValueT], - additional_options: list[str] = [], + additional_options: list[str] | None = None, ) -> None: + if additional_options is None: + additional_options = [] + self._separator = '' self._data = data self._additional_options = additional_options diff --git a/archinstall/lib/mirror/mirror_menu.py b/archinstall/lib/mirror/mirror_menu.py index 6c5de14ad5..af83c9f522 100644 --- a/archinstall/lib/mirror/mirror_menu.py +++ b/archinstall/lib/mirror/mirror_menu.py @@ -337,7 +337,10 @@ async def select_mirror_regions( return selected_mirrors -async def add_custom_mirror_servers(preset: list[CustomServer] = []) -> list[CustomServer]: +async def add_custom_mirror_servers(preset: list[CustomServer] | None = None) -> list[CustomServer]: + if preset is None: + preset = [] + custom_mirrors = await CustomMirrorServersList(preset).show() if not custom_mirrors: @@ -346,7 +349,10 @@ async def add_custom_mirror_servers(preset: list[CustomServer] = []) -> list[Cus return custom_mirrors -async def select_custom_mirror(preset: list[CustomRepository] = []) -> list[CustomRepository]: +async def select_custom_mirror(preset: list[CustomRepository] | None = None) -> list[CustomRepository]: + if preset is None: + preset = [] + custom_mirrors = await CustomMirrorRepositoriesList(preset).show() if not custom_mirrors: diff --git a/archinstall/lib/models/device.py b/archinstall/lib/models/device.py index 9e930de4ef..8319dc0876 100644 --- a/archinstall/lib/models/device.py +++ b/archinstall/lib/models/device.py @@ -562,7 +562,7 @@ def from_partition( partition: Partition, lsblk_info: LsblkInfo, fs_type: FilesystemType | None, - btrfs_subvol_infos: list[_BtrfsSubvolumeInfo] = [], + btrfs_subvol_infos: list[_BtrfsSubvolumeInfo] | None = None, ) -> Self: partition_type = PartitionType.get_type_from_code(partition.type) flags = [f for f in PartitionFlag if partition.getFlag(f.flag_id)] @@ -579,6 +579,9 @@ def from_partition( SectorSize(partition.disk.device.sectorSize, Unit.B), ) + if btrfs_subvol_infos is None: + btrfs_subvol_infos = [] + return cls( partition=partition, name=partition.get_name(), diff --git a/archinstall/lib/models/mirrors.py b/archinstall/lib/models/mirrors.py index f525294f87..825c842460 100644 --- a/archinstall/lib/models/mirrors.py +++ b/archinstall/lib/models/mirrors.py @@ -325,7 +325,7 @@ def repositories_config(self) -> str: def parse_args( cls, args: dict[str, Any], - backwards_compatible_repo: list[Repository] = [], + backwards_compatible_repo: list[Repository] | None = None, ) -> Self: config = cls() diff --git a/archinstall/lib/packages/packages.py b/archinstall/lib/packages/packages.py index 5b276f7634..865aa846a3 100644 --- a/archinstall/lib/packages/packages.py +++ b/archinstall/lib/packages/packages.py @@ -119,9 +119,15 @@ def _parse_package_output[PackageType: (AvailablePackage, LocalPackage)]( async def select_additional_packages( - preset: list[str] = [], - repositories: set[Repository] = set(), + preset: list[str] | None = None, + repositories: set[Repository] | None = None, ) -> list[str]: + if preset is None: + preset = [] + + if repositories is None: + repositories = set() + repositories |= {Repository.Core, Repository.Extra} respos_text = ', '.join(r.value for r in repositories) diff --git a/archinstall/lib/profile/profiles_handler.py b/archinstall/lib/profile/profiles_handler.py index b543b0ae04..eb54671642 100644 --- a/archinstall/lib/profile/profiles_handler.py +++ b/archinstall/lib/profile/profiles_handler.py @@ -353,12 +353,12 @@ def _find_available_profiles(self) -> list[Profile]: self._verify_unique_profile_names(profiles) return profiles - def reset_top_level_profiles(self, exclude: list[Profile] = []) -> None: + def reset_top_level_profiles(self, exclude: list[Profile] | None = None) -> None: """ Reset all top level profile configurations, this is usually necessary when a new top level profile is selected """ - excluded_profiles = [p.name for p in exclude] + excluded_profiles = [p.name for p in exclude] if exclude is not None else [] for profile in self.get_top_level_profiles(): if profile.name not in excluded_profiles: profile.reset() diff --git a/archinstall/lib/user/user_menu.py b/archinstall/lib/user/user_menu.py index 8e6e48fd55..1aa5649844 100644 --- a/archinstall/lib/user/user_menu.py +++ b/archinstall/lib/user/user_menu.py @@ -108,7 +108,10 @@ async def _add_user(self) -> User | None: return User(username, password, sudo) -async def select_users(prompt: str = '', preset: list[User] = []) -> list[User]: +async def select_users(prompt: str = '', preset: list[User] | None = None) -> list[User]: + if preset is None: + preset = [] + users = await UserList(prompt, preset).show() if users is None: diff --git a/archinstall/lib/utils/format.py b/archinstall/lib/utils/format.py index 1edfa3c6cd..df63b3738f 100644 --- a/archinstall/lib/utils/format.py +++ b/archinstall/lib/utils/format.py @@ -49,13 +49,16 @@ def as_key_value_pair( def _get_values( o: DataclassInstance, class_formatter: str | Callable | None = None, # type: ignore[type-arg] # pyright: ignore[reportMissingTypeArgument] - filter_list: list[str] = [], + filter_list: list[str] | None = None, ) -> dict[str, Any]: """ the original values returned a dataclass as dict thru the call to some specific methods this version allows thru the parameter class_formatter to call a dynamically selected formatting method. Can transmit a filter list to the class_formatter, """ + if filter_list is None: + filter_list = [] + if class_formatter: # if invoked per reference it has to be a standard function or a classmethod. # A method of an instance does not make sense @@ -80,7 +83,7 @@ def _get_values( def as_table( obj: list[Any], class_formatter: str | Callable | None = None, # type: ignore[type-arg] - filter_list: list[str] = [], + filter_list: list[str] | None = None, capitalize: bool = False, ) -> str: """variant of as_table (subtly different code) which has two additional parameters @@ -91,6 +94,9 @@ def as_table( is for compatibility with a print statement As_table_filter can be a drop in replacement for as_table """ + if filter_list is None: + filter_list = [] + raw_data = [_get_values(o, class_formatter, filter_list) for o in obj] # determine the maximum column size diff --git a/pyproject.toml b/pyproject.toml index 74ef602c7a..aea9a05921 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -238,7 +238,6 @@ select = [ ] ignore = [ - "B006", # mutable-argument-default "B008", # function-call-in-default-argument "B904", # raise-without-from-inside-except "B905", # zip-without-explicit-strict