From 6d61214bba2fc30de4eb8f4d8090c4dc4d011bdd Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Sat, 3 Oct 2026 15:03:31 -0700 Subject: [PATCH] Fix: satisfy pyrefly in test_pdf_ops and clarify pdf_ops docstrings Co-Authored-By: Claude Sonnet 5.5 --- src/documents/pdf_ops.py | 8 ++++++-- src/documents/tests/test_pdf_ops.py | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/documents/pdf_ops.py b/src/documents/pdf_ops.py index a8abbcd16..c35a9b2f4 100644 --- a/src/documents/pdf_ops.py +++ b/src/documents/pdf_ops.py @@ -39,7 +39,10 @@ def _require_positive(pages: Iterable[int]) -> None: def rotate_pdf(src: Path, dst: Path, degrees: int) -> None: - """Rotate every page relatively, in place, keeping document-level data.""" + """ + Rotate every page relatively on the opened document, not a rebuild, so Info, + XMP and outlines are kept. ``src`` is not modified. + """ with pikepdf.open(src) as pdf: for page in pdf.pages: page.rotate(degrees, relative=True) @@ -49,7 +52,8 @@ def rotate_pdf(src: Path, dst: Path, degrees: int) -> None: def remove_pages(src: Path, dst: Path, pages: Iterable[int]) -> None: """ - Remove 1-indexed pages in place, keeping document-level data. + Remove 1-indexed pages from the opened document, not a rebuild, so Info, XMP + and outlines are kept. ``src`` is not modified. Duplicates are ignored. Pages are removed highest first so earlier removals never shift the index of later ones. diff --git a/src/documents/tests/test_pdf_ops.py b/src/documents/tests/test_pdf_ops.py index 747d20946..2fdc54466 100644 --- a/src/documents/tests/test_pdf_ops.py +++ b/src/documents/tests/test_pdf_ops.py @@ -27,6 +27,7 @@ SIGNED = SRC_ROOT / "paperless" / "tests" / "samples" / "tesseract" / "signed.pd def _page_fingerprint(page: pikepdf.Page) -> str: contents = page.obj.get("/Contents") + assert contents is not None, "sample page has no /Contents" streams = list(contents) if isinstance(contents, pikepdf.Array) else [contents] return hashlib.sha1(b"".join(s.read_bytes() for s in streams)).hexdigest()