Skip to content

Commit

Permalink
fix: change cache file path's type to Path | str (#2192)
Browse files Browse the repository at this point in the history
* Force convert cache_file type to Path

* Refine type hint

* Refine all caches.py
  • Loading branch information
drunkwcodes authored Aug 20, 2023
1 parent 7582b92 commit 131953a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/pdm/models/caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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)

0 comments on commit 131953a

Please sign in to comment.