From 131953a645146a3ac2ecad7001993ec1c5b5eba8 Mon Sep 17 00:00:00 2001 From: drunkwcodes <36228443+drunkwcodes@users.noreply.github.com> Date: Sun, 20 Aug 2023 16:46:32 +0800 Subject: [PATCH] fix: change cache file path's type to Path | str (#2192) * Force convert cache_file type to Path * Refine type hint * Refine all caches.py --- src/pdm/models/caches.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pdm/models/caches.py b/src/pdm/models/caches.py index 64d8f8bdc0..c98e1ca188 100644 --- a/src/pdm/models/caches.py +++ b/src/pdm/models/caches.py @@ -31,8 +31,8 @@ class JSONFileCache(Generic[KT, VT]): """A file cache that stores key-value pairs in a json file.""" - def __init__(self, cache_file: Path) -> None: - self.cache_file = cache_file + def __init__(self, cache_file: Path | str) -> None: + self.cache_file = Path(cache_file) self._cache: dict[str, VT] = {} self._read_cache() @@ -118,8 +118,8 @@ class HashCache: FAVORITE_HASH = "sha256" STRONG_HASHES = ("sha256", "sha384", "sha512") - def __init__(self, directory: Path) -> None: - self.directory = directory + def __init__(self, directory: Path | str) -> None: + self.directory = Path(directory) def _read_from_link(self, link: Link, session: Session) -> Iterable[bytes]: if link.is_file: @@ -192,8 +192,8 @@ class WheelCache: one sdist, the one with most preferred tag will be returned. """ - def __init__(self, directory: Path) -> None: - self.directory = directory + def __init__(self, directory: Path | str) -> None: + self.directory = Path(directory) self.ephemeral_directory = Path(create_tracked_tempdir(prefix="pdm-wheel-cache-")) def _get_candidates(self, path: Path) -> Iterable[Path]: @@ -321,5 +321,5 @@ def delete(self, key: str) -> None: @lru_cache(maxsize=128) -def get_wheel_cache(directory: Path) -> WheelCache: +def get_wheel_cache(directory: Path | str) -> WheelCache: return WheelCache(directory)