From 551b5c227257b033037a4ac066fabd2ad56dbe65 Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Sat, 2 Mar 2024 07:42:39 +0100 Subject: [PATCH] fix for code validation --- radicale/storage/multifilesystem/base.py | 3 ++- radicale/storage/multifilesystem/cache.py | 3 ++- radicale/storage/multifilesystem/meta.py | 3 ++- radicale/storage/multifilesystem/sync.py | 3 ++- radicale/storage/multifilesystem/upload.py | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/radicale/storage/multifilesystem/base.py b/radicale/storage/multifilesystem/base.py index f6e56b3a..c2257b34 100644 --- a/radicale/storage/multifilesystem/base.py +++ b/radicale/storage/multifilesystem/base.py @@ -44,7 +44,8 @@ class CollectionBase(storage.BaseCollection): filesystem_path = pathutils.path_to_filesystem(folder, self.path) self._filesystem_path = filesystem_path - @types.contextmanager # type: ignore # for now, TODO fix for "mypy" + # TODO: better fix for "mypy" + @types.contextmanager # type: ignore def _atomic_write(self, path: str, mode: str = "w", newline: Optional[str] = None) -> Iterator[IO[AnyStr]]: # TODO: Overload with Literal when dropping support for Python < 3.8 diff --git a/radicale/storage/multifilesystem/cache.py b/radicale/storage/multifilesystem/cache.py index 086f2ac3..fc6b10f6 100644 --- a/radicale/storage/multifilesystem/cache.py +++ b/radicale/storage/multifilesystem/cache.py @@ -86,7 +86,8 @@ class CollectionPartCache(CollectionBase): content = self._item_cache_content(item) self._storage._makedirs_synced(cache_folder) # Race: Other processes might have created and locked the file. - with contextlib.suppress(PermissionError), self._atomic_write( # type: ignore # for now, TODO fix for "mypy" + # TODO: better fix for "mypy" + with contextlib.suppress(PermissionError), self._atomic_write( # type: ignore os.path.join(cache_folder, href), "wb") as fo: fb = cast(BinaryIO, fo) pickle.dump((cache_hash, *content), fb) diff --git a/radicale/storage/multifilesystem/meta.py b/radicale/storage/multifilesystem/meta.py index 47c8323e..577bfa14 100644 --- a/radicale/storage/multifilesystem/meta.py +++ b/radicale/storage/multifilesystem/meta.py @@ -61,6 +61,7 @@ class CollectionPartMeta(CollectionBase): return self._meta_cache if key is None else self._meta_cache.get(key) def set_meta(self, props: Mapping[str, str]) -> None: - with self._atomic_write(self._props_path, "w") as fo: # type: ignore # for now, TODO fix for "mypy" + # TODO: better fix for "mypy" + with self._atomic_write(self._props_path, "w") as fo: # type: ignore f = cast(TextIO, fo) json.dump(props, f, sort_keys=True) diff --git a/radicale/storage/multifilesystem/sync.py b/radicale/storage/multifilesystem/sync.py index 75eae84a..7f2f8223 100644 --- a/radicale/storage/multifilesystem/sync.py +++ b/radicale/storage/multifilesystem/sync.py @@ -95,7 +95,8 @@ class CollectionPartSync(CollectionPartCache, CollectionPartHistory, self._storage._makedirs_synced(token_folder) try: # Race: Other processes might have created and locked the file. - with self._atomic_write(token_path, "wb") as fo: # type: ignore # for now, TODO fix for "mypy" + # TODO: better fix for "mypy" + with self._atomic_write(token_path, "wb") as fo: # type: ignore fb = cast(BinaryIO, fo) pickle.dump(state, fb) except PermissionError: diff --git a/radicale/storage/multifilesystem/upload.py b/radicale/storage/multifilesystem/upload.py index a91f83b7..58a2a5e1 100644 --- a/radicale/storage/multifilesystem/upload.py +++ b/radicale/storage/multifilesystem/upload.py @@ -43,7 +43,8 @@ class CollectionPartUpload(CollectionPartGet, CollectionPartCache, raise ValueError("Failed to store item %r in collection %r: %s" % (href, self.path, e)) from e path = pathutils.path_to_filesystem(self._filesystem_path, href) - with self._atomic_write(path, newline="") as fo: # type: ignore # for now, TODO fix for "mypy" + # TODO: better fix for "mypy" + with self._atomic_write(path, newline="") as fo: # type: ignore f = cast(TextIO, fo) f.write(item.serialize()) # Clean the cache after the actual item is stored, or the cache entry