diff --git a/paperqa/contrib/zotero.py b/paperqa/contrib/zotero.py index c9dd94ff..5b69776a 100644 --- a/paperqa/contrib/zotero.py +++ b/paperqa/contrib/zotero.py @@ -15,7 +15,7 @@ " `pip install paper-qa[zotero]`." ) from e from paperqa.paths import PAPERQA_DIR -from paperqa.utils import StrPath, count_pdf_pages +from paperqa.utils import count_pdf_pages class ZoteroPaper(BaseModel): @@ -71,7 +71,7 @@ def __init__( library_type: str = "user", library_id: str | None = None, api_key: str | None = None, - storage: StrPath | None = None, + storage: str | os.PathLike | None = None, **kwargs, ): self.logger = logging.getLogger("ZoteroDB") @@ -104,7 +104,7 @@ def __init__( storage = PAPERQA_DIR / "zotero" self.logger.info(f"Using cache location: {storage}") - self.storage = storage + self.storage = Path(storage) super().__init__( library_type=library_type, library_id=library_id, api_key=api_key, **kwargs @@ -130,7 +130,7 @@ def get_pdf(self, item: dict) -> Path | None: if pdf_key is None: return None - pdf_path: Path = Path(self.storage / (pdf_key + ".pdf")) # type: ignore[operator] + pdf_path = self.storage / (pdf_key + ".pdf") if not pdf_path.exists(): pdf_path.parent.mkdir(parents=True, exist_ok=True) diff --git a/paperqa/utils.py b/paperqa/utils.py index 4e3ce428..9ebf7508 100644 --- a/paperqa/utils.py +++ b/paperqa/utils.py @@ -36,9 +36,6 @@ logger = logging.getLogger(__name__) -StrPath = str | Path - - class ImpossibleParsingError(Exception): """Error to throw when a parsing is impossible.""" @@ -87,7 +84,7 @@ def strings_similarity(s1: str, s2: str) -> float: return len(ss1.intersection(ss2)) / len(ss1.union(ss2)) -def count_pdf_pages(file_path: StrPath) -> int: +def count_pdf_pages(file_path: str | os.PathLike) -> int: with pymupdf.open(file_path) as doc: return len(doc) @@ -98,7 +95,7 @@ def hexdigest(data: str | bytes) -> str: return hashlib.md5(data).hexdigest() # noqa: S324 -def md5sum(file_path: StrPath) -> str: +def md5sum(file_path: str | os.PathLike) -> str: with open(file_path, "rb") as f: return hexdigest(f.read())