Remove remaining deprecated typing.Dict and typing.List usage (#2859)

This commit is contained in:
correctmost 2024-11-18 04:02:35 -05:00 committed by GitHub
parent 41e5a0fcfd
commit 9626965982
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 74 additions and 75 deletions

View File

@ -5,8 +5,9 @@ import os
import logging import logging
import time import time
import uuid import uuid
from collections.abc import Iterable
from pathlib import Path from pathlib import Path
from typing import List, Dict, Any, Optional, TYPE_CHECKING, Literal, Iterable from typing import Any, Optional, TYPE_CHECKING, Literal
from parted import ( from parted import (
Disk, Geometry, FileSystem, Disk, Geometry, FileSystem,
@ -37,11 +38,11 @@ class DeviceHandler:
_TMP_BTRFS_MOUNT = Path('/mnt/arch_btrfs') _TMP_BTRFS_MOUNT = Path('/mnt/arch_btrfs')
def __init__(self) -> None: def __init__(self) -> None:
self._devices: Dict[Path, BDevice] = {} self._devices: dict[Path, BDevice] = {}
self.load_devices() self.load_devices()
@property @property
def devices(self) -> List[BDevice]: def devices(self) -> list[BDevice]:
return list(self._devices.values()) return list(self._devices.values())
def load_devices(self) -> None: def load_devices(self) -> None:
@ -195,11 +196,11 @@ class DeviceHandler:
self, self,
dev_path: Path, dev_path: Path,
lsblk_info: Optional[LsblkInfo] = None lsblk_info: Optional[LsblkInfo] = None
) -> List[_BtrfsSubvolumeInfo]: ) -> list[_BtrfsSubvolumeInfo]:
if not lsblk_info: if not lsblk_info:
lsblk_info = get_lsblk_info(dev_path) lsblk_info = get_lsblk_info(dev_path)
subvol_infos: List[_BtrfsSubvolumeInfo] = [] subvol_infos: list[_BtrfsSubvolumeInfo] = []
if not lsblk_info.mountpoint: if not lsblk_info.mountpoint:
self.mount(dev_path, self._TMP_BTRFS_MOUNT, create_target_mountpoint=True) self.mount(dev_path, self._TMP_BTRFS_MOUNT, create_target_mountpoint=True)
@ -247,7 +248,7 @@ class DeviceHandler:
self, self,
fs_type: FilesystemType, fs_type: FilesystemType,
path: Path, path: Path,
additional_parted_options: List[str] = [] additional_parted_options: list[str] = []
) -> None: ) -> None:
mkfs_type = fs_type.value mkfs_type = fs_type.value
options = [] options = []
@ -561,8 +562,8 @@ class DeviceHandler:
def create_lvm_btrfs_subvolumes( def create_lvm_btrfs_subvolumes(
self, self,
path: Path, path: Path,
btrfs_subvols: List[SubvolumeModification], btrfs_subvols: list[SubvolumeModification],
mount_options: List[str] mount_options: list[str]
) -> None: ) -> None:
info(f'Creating subvolumes: {path}') info(f'Creating subvolumes: {path}')
@ -702,7 +703,7 @@ class DeviceHandler:
target_mountpoint: Path, target_mountpoint: Path,
mount_fs: Optional[str] = None, mount_fs: Optional[str] = None,
create_target_mountpoint: bool = True, create_target_mountpoint: bool = True,
options: List[str] = [] options: list[str] = []
) -> None: ) -> None:
if create_target_mountpoint and not target_mountpoint.exists(): if create_target_mountpoint and not target_mountpoint.exists():
target_mountpoint.mkdir(parents=True, exist_ok=True) target_mountpoint.mkdir(parents=True, exist_ok=True)
@ -750,8 +751,8 @@ class DeviceHandler:
debug(f'Unmounting mountpoint: {path}') debug(f'Unmounting mountpoint: {path}')
SysCommand(cmd + [str(path)]) SysCommand(cmd + [str(path)])
def detect_pre_mounted_mods(self, base_mountpoint: Path) -> List[DeviceModification]: def detect_pre_mounted_mods(self, base_mountpoint: Path) -> list[DeviceModification]:
part_mods: Dict[Path, List[PartitionModification]] = {} part_mods: dict[Path, list[PartitionModification]] = {}
for device in self.devices: for device in self.devices:
for part_info in device.partition_infos: for part_info in device.partition_infos:
@ -769,7 +770,7 @@ class DeviceHandler:
part_mods[path].append(part_mod) part_mods[path].append(part_mod)
break break
device_mods: List[DeviceModification] = [] device_mods: list[DeviceModification] = []
for device_path, mods in part_mods.items(): for device_path, mods in part_mods.items():
device_mod = DeviceModification(self._devices[device_path], False, mods) device_mod = DeviceModification(self._devices[device_path], False, mods)
device_mods.append(device_mod) device_mods.append(device_mod)

View File

@ -6,7 +6,7 @@ import uuid
from dataclasses import dataclass, field from dataclasses import dataclass, field
from enum import Enum from enum import Enum
from pathlib import Path from pathlib import Path
from typing import Optional, List, Dict, TYPE_CHECKING, Any from typing import Optional, TYPE_CHECKING, Any
from typing import Union from typing import Union
import parted import parted
@ -40,20 +40,20 @@ class DiskLayoutType(Enum):
@dataclass @dataclass
class DiskLayoutConfiguration: class DiskLayoutConfiguration:
config_type: DiskLayoutType config_type: DiskLayoutType
device_modifications: List[DeviceModification] = field(default_factory=list) device_modifications: list[DeviceModification] = field(default_factory=list)
lvm_config: Optional[LvmConfiguration] = None lvm_config: Optional[LvmConfiguration] = None
# used for pre-mounted config # used for pre-mounted config
mountpoint: Optional[Path] = None mountpoint: Optional[Path] = None
def json(self) -> Dict[str, Any]: def json(self) -> dict[str, Any]:
if self.config_type == DiskLayoutType.Pre_mount: if self.config_type == DiskLayoutType.Pre_mount:
return { return {
'config_type': self.config_type.value, 'config_type': self.config_type.value,
'mountpoint': str(self.mountpoint) 'mountpoint': str(self.mountpoint)
} }
else: else:
config: Dict[str, Any] = { config: dict[str, Any] = {
'config_type': self.config_type.value, 'config_type': self.config_type.value,
'device_modifications': [mod.json() for mod in self.device_modifications], 'device_modifications': [mod.json() for mod in self.device_modifications],
} }
@ -64,10 +64,10 @@ class DiskLayoutConfiguration:
return config return config
@classmethod @classmethod
def parse_arg(cls, disk_config: Dict[str, Any]) -> Optional[DiskLayoutConfiguration]: def parse_arg(cls, disk_config: dict[str, Any]) -> Optional[DiskLayoutConfiguration]:
from .device_handler import device_handler from .device_handler import device_handler
device_modifications: List[DeviceModification] = [] device_modifications: list[DeviceModification] = []
config_type = disk_config.get('config_type', None) config_type = disk_config.get('config_type', None)
if not config_type: if not config_type:
@ -109,7 +109,7 @@ class DiskLayoutConfiguration:
device=device device=device
) )
device_partitions: List[PartitionModification] = [] device_partitions: list[PartitionModification] = []
for partition in entry.get('partitions', []): for partition in entry.get('partitions', []):
device_partition = PartitionModification( device_partition = PartitionModification(
@ -166,11 +166,11 @@ class Unit(Enum):
sectors = 'sectors' # size in sector sectors = 'sectors' # size in sector
@staticmethod @staticmethod
def get_all_units() -> List[str]: def get_all_units() -> list[str]:
return [u.name for u in Unit] return [u.name for u in Unit]
@staticmethod @staticmethod
def get_si_units() -> List[Unit]: def get_si_units() -> list[Unit]:
return [u for u in Unit if 'i' not in u.name and u.name != 'sectors'] return [u for u in Unit if 'i' not in u.name and u.name != 'sectors']
@ -188,14 +188,14 @@ class SectorSize:
def default() -> SectorSize: def default() -> SectorSize:
return SectorSize(512, Unit.B) return SectorSize(512, Unit.B)
def json(self) -> Dict[str, Any]: def json(self) -> dict[str, Any]:
return { return {
'value': self.value, 'value': self.value,
'unit': self.unit.name, 'unit': self.unit.name,
} }
@classmethod @classmethod
def parse_args(cls, arg: Dict[str, Any]) -> SectorSize: def parse_args(cls, arg: dict[str, Any]) -> SectorSize:
return SectorSize( return SectorSize(
arg['value'], arg['value'],
Unit[arg['unit']] Unit[arg['unit']]
@ -218,7 +218,7 @@ class Size:
if not isinstance(self.sector_size, SectorSize): if not isinstance(self.sector_size, SectorSize):
raise ValueError('sector size must be of type SectorSize') raise ValueError('sector size must be of type SectorSize')
def json(self) -> Dict[str, Any]: def json(self) -> dict[str, Any]:
return { return {
'value': self.value, 'value': self.value,
'unit': self.unit.name, 'unit': self.unit.name,
@ -226,7 +226,7 @@ class Size:
} }
@classmethod @classmethod
def parse_args(cls, size_arg: Dict[str, Any]) -> Size: def parse_args(cls, size_arg: dict[str, Any]) -> Size:
sector_size = size_arg['sector_size'] sector_size = size_arg['sector_size']
return Size( return Size(
@ -345,20 +345,20 @@ class _PartitionInfo:
path: Path path: Path
start: Size start: Size
length: Size length: Size
flags: List[PartitionFlag] flags: list[PartitionFlag]
partn: Optional[int] partn: Optional[int]
partuuid: Optional[str] partuuid: Optional[str]
uuid: Optional[str] uuid: Optional[str]
disk: Disk disk: Disk
mountpoints: List[Path] mountpoints: list[Path]
btrfs_subvol_infos: List[_BtrfsSubvolumeInfo] = field(default_factory=list) btrfs_subvol_infos: list[_BtrfsSubvolumeInfo] = field(default_factory=list)
@property @property
def sector_size(self) -> SectorSize: def sector_size(self) -> SectorSize:
sector_size = self.partition.geometry.device.sectorSize sector_size = self.partition.geometry.device.sectorSize
return SectorSize(sector_size, Unit.B) return SectorSize(sector_size, Unit.B)
def table_data(self) -> Dict[str, Any]: def table_data(self) -> dict[str, Any]:
end = self.start + self.length end = self.start + self.length
part_info = { part_info = {
@ -385,8 +385,8 @@ class _PartitionInfo:
partn: Optional[int], partn: Optional[int],
partuuid: Optional[str], partuuid: Optional[str],
uuid: Optional[str], uuid: Optional[str],
mountpoints: List[Path], mountpoints: list[Path],
btrfs_subvol_infos: List[_BtrfsSubvolumeInfo] = [] btrfs_subvol_infos: list[_BtrfsSubvolumeInfo] = []
) -> _PartitionInfo: ) -> _PartitionInfo:
partition_type = PartitionType.get_type_from_code(partition.type) partition_type = PartitionType.get_type_from_code(partition.type)
flags = [f for f in PartitionFlag if partition.getFlag(f.value)] flags = [f for f in PartitionFlag if partition.getFlag(f.value)]
@ -427,12 +427,12 @@ class _DeviceInfo:
path: Path path: Path
type: str type: str
total_size: Size total_size: Size
free_space_regions: List[DeviceGeometry] free_space_regions: list[DeviceGeometry]
sector_size: SectorSize sector_size: SectorSize
read_only: bool read_only: bool
dirty: bool dirty: bool
def table_data(self) -> Dict[str, Any]: def table_data(self) -> dict[str, Any]:
total_free_space = sum([region.get_length(unit=Unit.MiB) for region in self.free_space_regions]) total_free_space = sum([region.get_length(unit=Unit.MiB) for region in self.free_space_regions])
return { return {
'Model': self.model, 'Model': self.model,
@ -480,7 +480,7 @@ class SubvolumeModification:
return SubvolumeModification(info.name, mountpoint=info.mountpoint) return SubvolumeModification(info.name, mountpoint=info.mountpoint)
@classmethod @classmethod
def parse_args(cls, subvol_args: List[Dict[str, Any]]) -> List[SubvolumeModification]: def parse_args(cls, subvol_args: list[dict[str, Any]]) -> list[SubvolumeModification]:
mods = [] mods = []
for entry in subvol_args: for entry in subvol_args:
if not entry.get('name', None) or not entry.get('mountpoint', None): if not entry.get('name', None) or not entry.get('mountpoint', None):
@ -509,10 +509,10 @@ class SubvolumeModification:
return self.mountpoint == Path('/') return self.mountpoint == Path('/')
return False return False
def json(self) -> Dict[str, Any]: def json(self) -> dict[str, Any]:
return {'name': str(self.name), 'mountpoint': str(self.mountpoint)} return {'name': str(self.name), 'mountpoint': str(self.mountpoint)}
def table_data(self) -> Dict[str, Any]: def table_data(self) -> dict[str, Any]:
return self.json() return self.json()
@ -532,7 +532,7 @@ class DeviceGeometry:
def get_length(self, unit: Unit = Unit.sectors) -> int: def get_length(self, unit: Unit = Unit.sectors) -> int:
return self._geometry.getLength(unit.name) return self._geometry.getLength(unit.name)
def table_data(self) -> Dict[str, Any]: def table_data(self) -> dict[str, Any]:
start = Size(self._geometry.start, Unit.sectors, self._sector_size) start = Size(self._geometry.start, Unit.sectors, self._sector_size)
end = Size(self._geometry.end, Unit.sectors, self._sector_size) end = Size(self._geometry.end, Unit.sectors, self._sector_size)
length = Size(self._geometry.getLength(), Unit.sectors, self._sector_size) length = Size(self._geometry.getLength(), Unit.sectors, self._sector_size)
@ -553,7 +553,7 @@ class DeviceGeometry:
class BDevice: class BDevice:
disk: Disk disk: Disk
device_info: _DeviceInfo device_info: _DeviceInfo
partition_infos: List[_PartitionInfo] partition_infos: list[_PartitionInfo]
def __hash__(self) -> int: def __hash__(self) -> int:
return hash(self.disk.device.path) return hash(self.disk.device.path)
@ -674,9 +674,9 @@ class PartitionModification:
length: Size length: Size
fs_type: Optional[FilesystemType] = None fs_type: Optional[FilesystemType] = None
mountpoint: Optional[Path] = None mountpoint: Optional[Path] = None
mount_options: List[str] = field(default_factory=list) mount_options: list[str] = field(default_factory=list)
flags: List[PartitionFlag] = field(default_factory=list) flags: list[PartitionFlag] = field(default_factory=list)
btrfs_subvols: List[SubvolumeModification] = field(default_factory=list) btrfs_subvols: list[SubvolumeModification] = field(default_factory=list)
# only set if the device was created or exists # only set if the device was created or exists
dev_path: Optional[Path] = None dev_path: Optional[Path] = None
@ -813,7 +813,7 @@ class PartitionModification:
else: else:
self.set_flag(flag) self.set_flag(flag)
def json(self) -> Dict[str, Any]: def json(self) -> dict[str, Any]:
""" """
Called for configuration settings Called for configuration settings
""" """
@ -831,7 +831,7 @@ class PartitionModification:
'btrfs': [vol.json() for vol in self.btrfs_subvols] 'btrfs': [vol.json() for vol in self.btrfs_subvols]
} }
def table_data(self) -> Dict[str, Any]: def table_data(self) -> dict[str, Any]:
""" """
Called for displaying data in table format Called for displaying data in table format
""" """
@ -872,10 +872,10 @@ class LvmLayoutType(Enum):
@dataclass @dataclass
class LvmVolumeGroup: class LvmVolumeGroup:
name: str name: str
pvs: List[PartitionModification] pvs: list[PartitionModification]
volumes: List[LvmVolume] = field(default_factory=list) volumes: list[LvmVolume] = field(default_factory=list)
def json(self) -> Dict[str, Any]: def json(self) -> dict[str, Any]:
return { return {
'name': self.name, 'name': self.name,
'lvm_pvs': [p.obj_id for p in self.pvs], 'lvm_pvs': [p.obj_id for p in self.pvs],
@ -883,7 +883,7 @@ class LvmVolumeGroup:
} }
@staticmethod @staticmethod
def parse_arg(arg: Dict[str, Any], disk_config: DiskLayoutConfiguration) -> LvmVolumeGroup: def parse_arg(arg: dict[str, Any], disk_config: DiskLayoutConfiguration) -> LvmVolumeGroup:
lvm_pvs = [] lvm_pvs = []
for mod in disk_config.device_modifications: for mod in disk_config.device_modifications:
for part in mod.partitions: for part in mod.partitions:
@ -914,8 +914,8 @@ class LvmVolume:
fs_type: FilesystemType fs_type: FilesystemType
length: Size length: Size
mountpoint: Optional[Path] mountpoint: Optional[Path]
mount_options: List[str] = field(default_factory=list) mount_options: list[str] = field(default_factory=list)
btrfs_subvols: List[SubvolumeModification] = field(default_factory=list) btrfs_subvols: list[SubvolumeModification] = field(default_factory=list)
# volume group name # volume group name
vg_name: Optional[str] = None vg_name: Optional[str] = None
@ -973,7 +973,7 @@ class LvmVolume:
raise ValueError('Mountpoint is not specified') raise ValueError('Mountpoint is not specified')
@staticmethod @staticmethod
def parse_arg(arg: Dict[str, Any]) -> LvmVolume: def parse_arg(arg: dict[str, Any]) -> LvmVolume:
volume = LvmVolume( volume = LvmVolume(
status=LvmVolumeStatus(arg['status']), status=LvmVolumeStatus(arg['status']),
name=arg['name'], name=arg['name'],
@ -988,7 +988,7 @@ class LvmVolume:
return volume return volume
def json(self) -> Dict[str, Any]: def json(self) -> dict[str, Any]:
return { return {
'obj_id': self.obj_id, 'obj_id': self.obj_id,
'status': self.status.value, 'status': self.status.value,
@ -1000,7 +1000,7 @@ class LvmVolume:
'btrfs': [vol.json() for vol in self.btrfs_subvols] 'btrfs': [vol.json() for vol in self.btrfs_subvols]
} }
def table_data(self) -> Dict[str, Any]: def table_data(self) -> dict[str, Any]:
part_mod = { part_mod = {
'Type': self.status.value, 'Type': self.status.value,
'Name': self.name, 'Name': self.name,
@ -1055,7 +1055,7 @@ class LvmPVInfo:
@dataclass @dataclass
class LvmConfiguration: class LvmConfiguration:
config_type: LvmLayoutType config_type: LvmLayoutType
vol_groups: List[LvmVolumeGroup] vol_groups: list[LvmVolumeGroup]
def __post_init__(self) -> None: def __post_init__(self) -> None:
# make sure all volume groups have unique PVs # make sure all volume groups have unique PVs
@ -1066,14 +1066,14 @@ class LvmConfiguration:
raise ValueError('A PV cannot be used in multiple volume groups') raise ValueError('A PV cannot be used in multiple volume groups')
pvs.append(pv) pvs.append(pv)
def json(self) -> Dict[str, Any]: def json(self) -> dict[str, Any]:
return { return {
'config_type': self.config_type.value, 'config_type': self.config_type.value,
'vol_groups': [vol_gr.json() for vol_gr in self.vol_groups] 'vol_groups': [vol_gr.json() for vol_gr in self.vol_groups]
} }
@staticmethod @staticmethod
def parse_arg(arg: Dict[str, Any], disk_config: DiskLayoutConfiguration) -> LvmConfiguration: def parse_arg(arg: dict[str, Any], disk_config: DiskLayoutConfiguration) -> LvmConfiguration:
lvm_pvs = [] lvm_pvs = []
for mod in disk_config.device_modifications: for mod in disk_config.device_modifications:
for part in mod.partitions: for part in mod.partitions:
@ -1085,14 +1085,14 @@ class LvmConfiguration:
vol_groups=[LvmVolumeGroup.parse_arg(vol_group, disk_config) for vol_group in arg['vol_groups']], vol_groups=[LvmVolumeGroup.parse_arg(vol_group, disk_config) for vol_group in arg['vol_groups']],
) )
def get_all_pvs(self) -> List[PartitionModification]: def get_all_pvs(self) -> list[PartitionModification]:
pvs = [] pvs = []
for vg in self.vol_groups: for vg in self.vol_groups:
pvs += vg.pvs pvs += vg.pvs
return pvs return pvs
def get_all_volumes(self) -> List[LvmVolume]: def get_all_volumes(self) -> list[LvmVolume]:
volumes = [] volumes = []
for vg in self.vol_groups: for vg in self.vol_groups:
@ -1122,7 +1122,7 @@ class LvmConfiguration:
class DeviceModification: class DeviceModification:
device: BDevice device: BDevice
wipe: bool wipe: bool
partitions: List[PartitionModification] = field(default_factory=list) partitions: list[PartitionModification] = field(default_factory=list)
@property @property
def device_path(self) -> Path: def device_path(self) -> Path:
@ -1157,7 +1157,7 @@ class DeviceModification:
filtered = filter(lambda x: x.is_root(), self.partitions) filtered = filter(lambda x: x.is_root(), self.partitions)
return next(filtered, None) return next(filtered, None)
def json(self) -> Dict[str, Any]: def json(self) -> dict[str, Any]:
""" """
Called when generating configuration files Called when generating configuration files
""" """
@ -1175,7 +1175,7 @@ class EncryptionType(Enum):
LuksOnLvm = 'luks_on_lvm' LuksOnLvm = 'luks_on_lvm'
@classmethod @classmethod
def _encryption_type_mapper(cls) -> Dict[str, 'EncryptionType']: def _encryption_type_mapper(cls) -> dict[str, 'EncryptionType']:
return { return {
str(_('No Encryption')): EncryptionType.NoEncryption, str(_('No Encryption')): EncryptionType.NoEncryption,
str(_('LUKS')): EncryptionType.Luks, str(_('LUKS')): EncryptionType.Luks,
@ -1199,8 +1199,8 @@ class EncryptionType(Enum):
class DiskEncryption: class DiskEncryption:
encryption_type: EncryptionType = EncryptionType.NoEncryption encryption_type: EncryptionType = EncryptionType.NoEncryption
encryption_password: str = '' encryption_password: str = ''
partitions: List[PartitionModification] = field(default_factory=list) partitions: list[PartitionModification] = field(default_factory=list)
lvm_volumes: List[LvmVolume] = field(default_factory=list) lvm_volumes: list[LvmVolume] = field(default_factory=list)
hsm_device: Optional[Fido2Device] = None hsm_device: Optional[Fido2Device] = None
def __post_init__(self) -> None: def __post_init__(self) -> None:
@ -1217,8 +1217,8 @@ class DiskEncryption:
return dev in self.lvm_volumes and dev.mountpoint != Path('/') return dev in self.lvm_volumes and dev.mountpoint != Path('/')
return False return False
def json(self) -> Dict[str, Any]: def json(self) -> dict[str, Any]:
obj: Dict[str, Any] = { obj: dict[str, Any] = {
'encryption_type': self.encryption_type.value, 'encryption_type': self.encryption_type.value,
'partitions': [p.obj_id for p in self.partitions], 'partitions': [p.obj_id for p in self.partitions],
'lvm_volumes': [vol.obj_id for vol in self.lvm_volumes] 'lvm_volumes': [vol.obj_id for vol in self.lvm_volumes]
@ -1247,7 +1247,7 @@ class DiskEncryption:
def parse_arg( def parse_arg(
cls, cls,
disk_config: DiskLayoutConfiguration, disk_config: DiskLayoutConfiguration,
disk_encryption: Dict[str, Any], disk_encryption: dict[str, Any],
password: str = '' password: str = ''
) -> Optional['DiskEncryption']: ) -> Optional['DiskEncryption']:
if not cls.validate_enc(disk_config): if not cls.validate_enc(disk_config):
@ -1287,14 +1287,14 @@ class Fido2Device:
manufacturer: str manufacturer: str
product: str product: str
def json(self) -> Dict[str, str]: def json(self) -> dict[str, str]:
return { return {
'path': str(self.path), 'path': str(self.path),
'manufacturer': self.manufacturer, 'manufacturer': self.manufacturer,
'product': self.product 'product': self.product
} }
def table_data(self) -> Dict[str, str]: def table_data(self) -> dict[str, str]:
return { return {
'Path': str(self.path), 'Path': str(self.path),
'Manufacturer': self.manufacturer, 'Manufacturer': self.manufacturer,
@ -1302,7 +1302,7 @@ class Fido2Device:
} }
@classmethod @classmethod
def parse_arg(cls, arg: Dict[str, str]) -> 'Fido2Device': def parse_arg(cls, arg: dict[str, str]) -> 'Fido2Device':
return Fido2Device( return Fido2Device(
Path(arg['path']), Path(arg['path']),
arg['manufacturer'], arg['manufacturer'],
@ -1366,7 +1366,7 @@ def _fetch_lsblk_info(
dev_path: Optional[Union[Path, str]] = None, dev_path: Optional[Union[Path, str]] = None,
reverse: bool = False, reverse: bool = False,
full_dev_path: bool = False full_dev_path: bool = False
) -> List[LsblkInfo]: ) -> list[LsblkInfo]:
cmd = ['lsblk', '--json', '--bytes', '--output', ','.join(LsblkInfo.fields())] cmd = ['lsblk', '--json', '--bytes', '--output', ','.join(LsblkInfo.fields())]
if reverse: if reverse:
@ -1411,13 +1411,13 @@ def get_lsblk_info(
raise DiskError(f'lsblk failed to retrieve information for "{dev_path}"') raise DiskError(f'lsblk failed to retrieve information for "{dev_path}"')
def get_all_lsblk_info() -> List[LsblkInfo]: def get_all_lsblk_info() -> list[LsblkInfo]:
return _fetch_lsblk_info() return _fetch_lsblk_info()
def find_lsblk_info( def find_lsblk_info(
dev_path: Union[Path, str], dev_path: Union[Path, str],
info: List[LsblkInfo] info: list[LsblkInfo]
) -> Optional[LsblkInfo]: ) -> Optional[LsblkInfo]:
if isinstance(dev_path, str): if isinstance(dev_path, str):
dev_path = Path(dev_path) dev_path = Path(dev_path)
@ -1429,8 +1429,8 @@ def find_lsblk_info(
return None return None
def get_lsblk_by_mountpoint(mountpoint: Path, as_prefix: bool = False) -> List[LsblkInfo]: def get_lsblk_by_mountpoint(mountpoint: Path, as_prefix: bool = False) -> list[LsblkInfo]:
def _check(infos: List[LsblkInfo]) -> List[LsblkInfo]: def _check(infos: list[LsblkInfo]) -> list[LsblkInfo]:
devices = [] devices = []
for entry in infos: for entry in infos:
if as_prefix: if as_prefix:

View File

@ -194,13 +194,11 @@ select = [
ignore = [ ignore = [
"E722", # bare-except "E722", # bare-except
"PLW2901", # redefined-loop-name "PLW2901", # redefined-loop-name
"UP006", # non-pep585-annotation
"UP007", # non-pep604-annotation "UP007", # non-pep604-annotation
"UP027", # unpacked-list-comprehension "UP027", # unpacked-list-comprehension
"UP028", # yield-in-for-loop "UP028", # yield-in-for-loop
"UP031", # printf-string-formatting "UP031", # printf-string-formatting
"UP032", # f-string "UP032", # f-string
"UP035", # deprecated-import
"UP037", # quoted-annotation "UP037", # quoted-annotation
"W191", # tab-indentation "W191", # tab-indentation
] ]