diff --git a/archinstall/lib/disk/device_handler.py b/archinstall/lib/disk/device_handler.py index 8a6ce739b6..1e5d52224a 100644 --- a/archinstall/lib/disk/device_handler.py +++ b/archinstall/lib/disk/device_handler.py @@ -183,7 +183,7 @@ def get_uuid_for_path(self, path: Path) -> str | None: def get_btrfs_info( self, - dev_path: Path, + dev_path: Path | str, lsblk_info: LsblkInfo | None = None, ) -> list[_BtrfsSubvolumeInfo]: if not lsblk_info: diff --git a/archinstall/lib/disk/utils.py b/archinstall/lib/disk/utils.py index 445dc69412..32b69130ef 100644 --- a/archinstall/lib/disk/utils.py +++ b/archinstall/lib/disk/utils.py @@ -137,7 +137,7 @@ def udev_sync() -> None: def mount( - dev_path: Path, + dev_path: Path | str, target_mountpoint: Path, mount_fs: str | None = None, create_target_mountpoint: bool = True, @@ -173,7 +173,7 @@ def mount( raise DiskError(f'Could not mount {dev_path}: {command}\n{err.message}') -def umount(mountpoint: Path, recursive: bool = False) -> None: +def umount(mountpoint: Path | str, recursive: bool = False) -> None: lsblk_info = get_lsblk_info(mountpoint) if not lsblk_info.mountpoints: diff --git a/archinstall/lib/models/device.py b/archinstall/lib/models/device.py index 8319dc0876..b266eaeb00 100644 --- a/archinstall/lib/models/device.py +++ b/archinstall/lib/models/device.py @@ -574,7 +574,7 @@ def from_partition( ) length = Size( - int(partition.getLength(unit='B')), + partition.getLength(unit='B'), Unit.B, SectorSize(partition.disk.device.sectorSize, Unit.B), ) @@ -646,7 +646,7 @@ def from_disk(cls, disk: Disk) -> Self: path=Path(device.path), type=device_type, sector_size=sector_size, - total_size=Size(int(device.getLength(unit='B')), Unit.B, sector_size), + total_size=Size(device.getLength(unit='B'), Unit.B, sector_size), free_space_regions=free_space, read_only=device.readOnly, dirty=device.dirty, @@ -764,12 +764,11 @@ def get_type_from_code(code: int) -> PartitionType: debug(f'Partition code not supported: {code}') return PartitionType._UNKNOWN - def get_partition_code(self) -> int | None: - if self == PartitionType.PRIMARY: - return parted.PARTITION_NORMAL - elif self == PartitionType.BOOT: + def get_partition_code(self) -> int: + if self == PartitionType.BOOT: return parted.PARTITION_BOOT - return None + + return parted.PARTITION_NORMAL @dataclass(frozen=True) diff --git a/pyproject.toml b/pyproject.toml index 4dc0d46d77..2c795a40ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -105,16 +105,6 @@ disallow_any_explicit = true module = "archinstall.lib.*" warn_return_any = false -[[tool.mypy.overrides]] -module = "archinstall.lib.disk.*" -# 'Any' imports are allowed because pyparted doesn't have type hints -disallow_any_unimported = false - -[[tool.mypy.overrides]] -module = "archinstall.lib.models.*" -# 'Any' imports are allowed because pyparted doesn't have type hints -disallow_any_unimported = false - [[tool.mypy.overrides]] module = "archinstall.lib.packages" disallow_any_explicit = true @@ -123,12 +113,6 @@ disallow_any_explicit = true module = "archinstall.lib.utils" disallow_any_explicit = true -[[tool.mypy.overrides]] -module = [ - "parted", -] -ignore_missing_imports = true - [tool.bandit] targets = ["archinstall"] exclude = ["/tests"] @@ -178,10 +162,6 @@ init-import = true [tool.pyrefly] python-version = "3.14" -replace-imports-with-any = [ - "parted", # pyparted doesn't have type hints -] - [tool.pyrefly.errors] # Enable some additional rules that are disabled by default implicit-abstract-class = true diff --git a/stubs/parted/__init__.pyi b/stubs/parted/__init__.pyi new file mode 100644 index 0000000000..2c4199dda2 --- /dev/null +++ b/stubs/parted/__init__.pyi @@ -0,0 +1,88 @@ +DEVICE_UNKNOWN: int +PARTITION_NORMAL: int +PARTITION_BOOT: int +PARTITION_ESP: int +PARTITION_BLS_BOOT: int +PARTITION_LINUX_HOME: int +PARTITION_SWAP: int + +class IOException(Exception): ... +class DiskException(Exception): ... +class PartitionException(Exception): ... +class Constraint: ... + +class Device: + @property + def model(self) -> str: ... + @property + def path(self) -> str: ... + @property + def type(self) -> int: ... + @property + def sectorSize(self) -> int: ... + @property + def readOnly(self) -> bool: ... + @property + def dirty(self) -> bool: ... + @property + def optimalAlignedConstraint(self) -> Constraint: ... + def getLength(self, unit: str = ...) -> int: ... + +class Geometry: + start: int + end: int + + def __init__(self, device: Device, start: int, length: int) -> None: ... + @property + def device(self) -> Device: ... + def getLength(self, unit: str = ...) -> int: ... + +class FileSystem: + def __init__( + self, + type: str, # pylint: disable=redefined-builtin + geometry: Geometry, + ) -> None: ... + @property + def type(self) -> str: ... + +class Disk: + @property + def device(self) -> Device: ... + @property + def type(self) -> str: ... + @property + def partitions(self) -> list[Partition]: ... + def commit(self) -> None: ... + def addPartition(self, partition: Partition, constraint: Constraint) -> None: ... + def deletePartition(self, partition: Partition) -> None: ... + def getFreeSpaceRegions(self) -> list[Geometry]: ... + +class Partition: + fileSystem: FileSystem | None + geometry: Geometry + type: int + type_uuid: bytes + + def __init__( + self, + disk: Disk, + type: int, # pylint: disable=redefined-builtin + fs: FileSystem, + geometry: Geometry, + ) -> None: ... + @property + def disk(self) -> Disk: ... + @property + def path(self) -> str: ... + def get_name(self) -> str: ... + def getFlag(self, flag: int) -> int: ... + def setFlag(self, flag: int) -> None: ... + def getLength(self, unit: str = ...) -> int: ... + +def getAllDevices() -> list[Device]: ... +def getDevice(device: str) -> Device: ... +def newDisk(device: Device) -> Disk: ... +def freshDisk(device: Device, label: str) -> Disk: ... + +devices: dict[int, str]