Skip to content

Commit

Permalink
Removed StrPath in favor of direct type hints (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbraza committed Sep 11, 2024
1 parent 45b206d commit cf1e540
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 4 additions & 4 deletions paperqa/contrib/zotero.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions paperqa/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
logger = logging.getLogger(__name__)


StrPath = str | Path


class ImpossibleParsingError(Exception):
"""Error to throw when a parsing is impossible."""

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

Expand All @@ -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())

Expand Down

0 comments on commit cf1e540

Please sign in to comment.