From 95e137f053caaa4c424915ef408cd2920dadc516 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 29 Dec 2025 17:15:16 +0100 Subject: fix types in fstrans --- fietsboek/fstrans.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fietsboek/fstrans.py b/fietsboek/fstrans.py index 13b0018..35cc992 100644 --- a/fietsboek/fstrans.py +++ b/fietsboek/fstrans.py @@ -68,7 +68,7 @@ import shutil import uuid from pathlib import Path -import transaction +import transaction # type: ignore from filelock import FileLock LOGGER = logging.getLogger(__name__) @@ -128,7 +128,7 @@ class WriteBytes(Action): def __init__(self, path: Path, data: bytes): self.path = path self.data = data - self.old = None + self.old: bytes | None = None def __repr__(self): return f"" @@ -152,7 +152,7 @@ class Unlink(Action): def __init__(self, path: Path): self.path = path - self.old = None + self.old: bytes | None = None def __repr__(self): return f"" @@ -162,7 +162,10 @@ class Unlink(Action): self.path.unlink() def undo(self): - self.path.write_bytes(self.old) + # This should not happen, unless an exception occurs when we read the + # file + if self.old is not None: + self.path.write_bytes(self.old) class MakeDir(Action): @@ -171,7 +174,7 @@ class MakeDir(Action): def __init__(self, path: Path, exist_ok: bool = False): self.path = path self.exist_ok = exist_ok - self.existed = None + self.existed: bool | None = None def __repr__(self): return f"" -- cgit v1.2.3