From 873525167164cd30e36c5d6b7b821cac231103d5 Mon Sep 17 00:00:00 2001 From: timeshifter Date: Tue, 6 Dec 2022 11:20:39 +0100 Subject: [PATCH] fix pyright lints --- zfs_backup.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/zfs_backup.py b/zfs_backup.py index 42a2bd9..24457c9 100755 --- a/zfs_backup.py +++ b/zfs_backup.py @@ -38,8 +38,6 @@ def main(): class Manager: """Controls the overall backup process.""" - _map_type: dict[Dataset, Dataset | None] - def __init__(self, local_pool: Pool, external_pool: ExternalPool): self._local_pool = local_pool self._external_pool = external_pool @@ -70,11 +68,11 @@ class Manager: continue ZFS.receive(stream, self._external_pool) - def _get_user_filtered_dataset_backup_map(self) -> _map_type: + def _get_user_filtered_dataset_backup_map(self) -> dict[Dataset, Dataset | None]: """Get the dataset map, let user confirm new datasets.""" return self._user_confirm_new_datasets(self._get_raw_dataset_map()) - def _user_confirm_new_datasets(self, dataset_map: _map_type) -> _map_type: + def _user_confirm_new_datasets(self, dataset_map: dict[Dataset, Dataset | None]) -> dict[Dataset, Dataset | None]: """For datasets that exist only locally, ask the user if he wants to back it up. If he doesn't, remove it from the dict. @@ -85,7 +83,7 @@ class Manager: if remote_dataset is not None or self._ask_user_confirmation(local_dataset) } - def _get_raw_dataset_map(self) -> _map_type: + def _get_raw_dataset_map(self) -> dict[Dataset, Dataset | None]: """Return map from local to remote datasets. If the local dataset has no remote match, set the remote dataset to None. @@ -171,7 +169,7 @@ class Manager: return common_snapshots[-1] @staticmethod - def _ask_user_confirmation(dataset: Dataset) -> bool: + def _ask_user_confirmation(dataset: Dataset) -> bool: # type: ignore (false positive) msg = f"Dataset {dataset.qualified_name} does not exist in backup pool. Backup? [y/n] " reply = "" while not reply: @@ -256,6 +254,7 @@ class ZFSPath: """Return the `zfs` path, but without the pool name.""" name = "/".join(self._elements[1:]) if self.is_snapshot: + assert self.snapshot_name name = "@".join([name, self.snapshot_name]) return name @@ -751,8 +750,8 @@ class Snapshot: def from_string(cls, qualified_name: str) -> Snapshot: return cls(ZFSPath.from_string(qualified_name)) - def __lt__(self, other: Snapshot) -> bool: - return self.snapshot_name < other.snapshot_name + def __gt__(self, other: Snapshot) -> bool: + return self.snapshot_name > other.snapshot_name def __repr__(self): return str(self._path) @@ -765,6 +764,7 @@ class Snapshot: @property def snapshot_name(self) -> str: + assert self._path.snapshot_name return self._path.snapshot_name def matches_regex(self, regex: str) -> bool: