Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions archinstall/lib/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from dataclasses import dataclass, field
from importlib.metadata import version
from pathlib import Path
from typing import Any
from typing import Any, Self
from urllib.request import Request, urlopen

from pydantic.dataclasses import dataclass as p_dataclass
Expand Down Expand Up @@ -131,7 +131,7 @@ def safe_json(self) -> dict[str, Any]:
return config

@classmethod
def from_config(cls, args_config: dict[str, Any], args: Arguments) -> 'ArchConfig':
def from_config(cls, args_config: dict[str, Any], args: Arguments) -> Self:
arch_config = cls()

arch_config.locale_config = LocaleConfiguration.parse_arg(args_config)
Expand Down
3 changes: 2 additions & 1 deletion archinstall/lib/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from enum import Enum
from functools import cached_property
from pathlib import Path
from typing import Self

from .exceptions import SysCallError
from .general import SysCommand
Expand All @@ -16,7 +17,7 @@ class CpuVendor(Enum):
_Unknown = 'unknown'

@classmethod
def get_vendor(cls, name: str) -> 'CpuVendor':
def get_vendor(cls, name: str) -> Self:
if vendor := getattr(cls, name, None):
return vendor
else:
Expand Down
10 changes: 5 additions & 5 deletions archinstall/lib/models/bootloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
from dataclasses import dataclass
from enum import Enum
from typing import Any
from typing import Any, Self

from archinstall.lib.translationhandler import tr

Expand Down Expand Up @@ -33,7 +33,7 @@ def json(self) -> str:
return self.value

@classmethod
def get_default(cls) -> Bootloader:
def get_default(cls) -> Self:
from ..args import arch_config_handler

if arch_config_handler.args.skip_boot:
Expand All @@ -44,7 +44,7 @@ def get_default(cls) -> Bootloader:
return cls.Grub

@classmethod
def from_arg(cls, bootloader: str, skip_boot: bool) -> Bootloader:
def from_arg(cls, bootloader: str, skip_boot: bool) -> Self:
# to support old configuration files
bootloader = bootloader.capitalize()

Expand All @@ -68,14 +68,14 @@ def json(self) -> dict[str, Any]:
return {'bootloader': self.bootloader.json(), 'uki': self.uki, 'removable': self.removable}

@classmethod
def parse_arg(cls, config: dict[str, Any], skip_boot: bool) -> BootloaderConfiguration:
def parse_arg(cls, config: dict[str, Any], skip_boot: bool) -> Self:
bootloader = Bootloader.from_arg(config.get('bootloader', ''), skip_boot)
uki = config.get('uki', False)
removable = config.get('removable', True)
return cls(bootloader=bootloader, uki=uki, removable=removable)

@classmethod
def get_default(cls) -> BootloaderConfiguration:
def get_default(cls) -> Self:
bootloader = Bootloader.get_default()
removable = SysInfo.has_uefi() and bootloader.has_removable_support()
uki = SysInfo.has_uefi() and bootloader.has_uki_support()
Expand Down
30 changes: 15 additions & 15 deletions archinstall/lib/models/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def parse_arg(
cls,
disk_config: _DiskLayoutConfigurationSerialization,
enc_password: Password | None = None,
) -> DiskLayoutConfiguration | None:
) -> Self | None:
from archinstall.lib.disk.device_handler import device_handler

device_modifications: list[DeviceModification] = []
Expand Down Expand Up @@ -223,7 +223,7 @@ def is_mbr(self) -> bool:
return self == PartitionTable.MBR

@classmethod
def default(cls) -> PartitionTable:
def default(cls) -> Self:
return cls.GPT if SysInfo.has_uefi() else cls.MBR


Expand Down Expand Up @@ -293,7 +293,7 @@ def json(self) -> _SectorSizeSerialization:
}

@classmethod
def parse_args(cls, arg: _SectorSizeSerialization) -> SectorSize:
def parse_args(cls, arg: _SectorSizeSerialization) -> Self:
return cls(
arg['value'],
Unit[arg['unit']],
Expand Down Expand Up @@ -330,7 +330,7 @@ def json(self) -> _SizeSerialization:
}

@classmethod
def parse_args(cls, size_arg: _SizeSerialization) -> Size:
def parse_args(cls, size_arg: _SizeSerialization) -> Self:
sector_size = size_arg['sector_size']

return cls(
Expand Down Expand Up @@ -537,7 +537,7 @@ def from_partition(
lsblk_info: LsblkInfo,
fs_type: FilesystemType | None,
btrfs_subvol_infos: list[_BtrfsSubvolumeInfo] = [],
) -> _PartitionInfo:
) -> Self:
partition_type = PartitionType.get_type_from_code(partition.type)
flags = [f for f in PartitionFlag if partition.getFlag(f.flag_id)]

Expand Down Expand Up @@ -595,7 +595,7 @@ def table_data(self) -> dict[str, str | int | bool]:
}

@classmethod
def from_disk(cls, disk: Disk) -> _DeviceInfo:
def from_disk(cls, disk: Disk) -> Self:
device = disk.device
if device.type == 18:
device_type = 'loop'
Expand Down Expand Up @@ -631,11 +631,11 @@ class SubvolumeModification:
mountpoint: Path | None = None

@classmethod
def from_existing_subvol_info(cls, info: _BtrfsSubvolumeInfo) -> SubvolumeModification:
def from_existing_subvol_info(cls, info: _BtrfsSubvolumeInfo) -> Self:
return cls(info.name, mountpoint=info.mountpoint)

@classmethod
def parse_args(cls, subvol_args: list[_SubvolumeModificationSerialization]) -> list[SubvolumeModification]:
def parse_args(cls, subvol_args: list[_SubvolumeModificationSerialization]) -> list[Self]:
mods = []
for entry in subvol_args:
if not entry.get('name', None) or not entry.get('mountpoint', None):
Expand Down Expand Up @@ -721,7 +721,7 @@ class PartitionType(Enum):
_Unknown = 'unknown'

@classmethod
def get_type_from_code(cls, code: int) -> PartitionType:
def get_type_from_code(cls, code: int) -> Self:
if code == parted.PARTITION_NORMAL:
return cls.Primary
else:
Expand Down Expand Up @@ -754,7 +754,7 @@ def description(self) -> str:
return self.alias or self.name.lower()

@classmethod
def from_string(cls, s: str) -> PartitionFlag | None:
def from_string(cls, s: str) -> Self | None:
s = s.lower()

for partition_flag in cls:
Expand Down Expand Up @@ -911,7 +911,7 @@ def safe_fs_type(self) -> FilesystemType:
return self.fs_type

@classmethod
def from_existing_partition(cls, partition_info: _PartitionInfo) -> PartitionModification:
def from_existing_partition(cls, partition_info: _PartitionInfo) -> Self:
if partition_info.btrfs_subvol_infos:
mountpoint = None
subvol_mods = []
Expand Down Expand Up @@ -1431,7 +1431,7 @@ class EncryptionType(Enum):
LuksOnLvm = 'luks_on_lvm'

@classmethod
def _encryption_type_mapper(cls) -> dict[str, 'EncryptionType']:
def _encryption_type_mapper(cls) -> dict[str, Self]:
return {
tr('No Encryption'): cls.NoEncryption,
tr('LUKS'): cls.Luks,
Expand All @@ -1440,7 +1440,7 @@ def _encryption_type_mapper(cls) -> dict[str, 'EncryptionType']:
}

@classmethod
def text_to_type(cls, text: str) -> 'EncryptionType':
def text_to_type(cls, text: str) -> Self:
mapping = cls._encryption_type_mapper()
return mapping[text]

Expand Down Expand Up @@ -1518,7 +1518,7 @@ def parse_arg(
disk_config: DiskLayoutConfiguration,
disk_encryption: _DiskEncryptionSerialization,
password: Password | None = None,
) -> 'DiskEncryption | None':
) -> Self | None:
if not cls.validate_enc(disk_config.device_modifications, disk_config.lvm_config):
return None

Expand Down Expand Up @@ -1580,7 +1580,7 @@ def table_data(self) -> dict[str, str]:
}

@classmethod
def parse_arg(cls, arg: _Fido2DeviceSerialization) -> 'Fido2Device':
def parse_arg(cls, arg: _Fido2DeviceSerialization) -> Self:
return cls(
Path(arg['path']),
arg['manufacturer'],
Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/models/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _load_config(self, args: dict[str, str]) -> None:
self.kb_layout = args['kb_layout']

@classmethod
def parse_arg(cls, args: dict[str, Any]) -> 'LocaleConfiguration':
def parse_arg(cls, args: dict[str, Any]) -> Self:
default = cls.default()

if 'locale_config' in args:
Expand Down
8 changes: 4 additions & 4 deletions archinstall/lib/models/mirrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import urllib.request
from dataclasses import dataclass, field
from enum import Enum
from typing import Any, TypedDict, override
from typing import Any, Self, TypedDict, override

from pydantic import BaseModel, field_validator, model_validator

Expand Down Expand Up @@ -191,7 +191,7 @@ def json(self) -> _CustomRepositorySerialization:
}

@classmethod
def parse_args(cls, args: list[dict[str, str]]) -> list['CustomRepository']:
def parse_args(cls, args: list[dict[str, str]]) -> list[Self]:
configs = []
for arg in args:
configs.append(
Expand All @@ -217,7 +217,7 @@ def json(self) -> dict[str, str]:
return {'url': self.url}

@classmethod
def parse_args(cls, args: list[dict[str, str]]) -> list['CustomServer']:
def parse_args(cls, args: list[dict[str, str]]) -> list[Self]:
configs = []
for arg in args:
configs.append(
Expand Down Expand Up @@ -304,7 +304,7 @@ def parse_args(
cls,
args: dict[str, Any],
backwards_compatible_repo: list[Repository] = [],
) -> 'MirrorConfiguration':
) -> Self:
config = cls()

mirror_regions = args.get('mirror_regions', [])
Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/models/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class WifiConfiguredNetwork:
flags: list[str]

@classmethod
def from_wpa_cli_output(cls, list_networks: str) -> list[WifiConfiguredNetwork]:
def from_wpa_cli_output(cls, list_networks: str) -> list[Self]:
"""
Example output from 'wpa_cli list_networks'

Expand Down
4 changes: 2 additions & 2 deletions archinstall/lib/models/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ class PackageGroup:
def from_available_packages(
cls,
packages: dict[str, AvailablePackage],
) -> dict[str, 'PackageGroup']:
pkg_groups: dict[str, 'PackageGroup'] = {}
) -> dict[str, Self]:
pkg_groups: dict[str, Self] = {}

for pkg in packages.values():
if 'None' in pkg.groups:
Expand Down
4 changes: 2 additions & 2 deletions archinstall/lib/models/profile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import TYPE_CHECKING, TypedDict
from typing import TYPE_CHECKING, Self, TypedDict

from archinstall.default_profiles.profile import GreeterType, Profile

Expand Down Expand Up @@ -33,7 +33,7 @@ def json(self) -> _ProfileConfigurationSerialization:
}

@classmethod
def parse_arg(cls, arg: _ProfileConfigurationSerialization) -> 'ProfileConfiguration':
def parse_arg(cls, arg: _ProfileConfigurationSerialization) -> Self:
from ..profile.profiles_handler import profile_handler

profile = profile_handler.parse_profile_config(arg['profile'])
Expand Down
10 changes: 5 additions & 5 deletions archinstall/lib/models/users.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass, field
from enum import Enum
from typing import NotRequired, TypedDict, override
from typing import NotRequired, Self, TypedDict, override

from archinstall.lib.translationhandler import tr

Expand Down Expand Up @@ -38,7 +38,7 @@ def color(self) -> str:
return 'green'

@classmethod
def strength(cls, password: str) -> 'PasswordStrength':
def strength(cls, password: str) -> Self:
digit = any(character.isdigit() for character in password)
upper = any(character.isupper() for character in password)
lower = any(character.islower() for character in password)
Expand All @@ -53,7 +53,7 @@ def _check_password_strength(
lower: bool,
symbol: bool,
length: int,
) -> 'PasswordStrength':
) -> Self:
# suggested evaluation
# https://github.com/archlinux/archinstall/issues/1304#issuecomment-1146768163
if digit and upper and lower and symbol:
Expand Down Expand Up @@ -185,8 +185,8 @@ def json(self) -> UserSerialization:
def parse_arguments(
cls,
args: list[UserSerialization],
) -> list['User']:
users: list[User] = []
) -> list[Self]:
users = []

for entry in args:
username = entry.get('username')
Expand Down