From 16227dcc331be8c5fcf70d8392c11e39d750a8e6 Mon Sep 17 00:00:00 2001 From: Daniel Holbach Date: Thu, 2 Jul 2026 20:50:04 +0200 Subject: [PATCH] fix: suppress pypdf EOF warnings in PDF rotation helpers pypdf emits "EOF marker not found" via warnings.warn() for slightly malformed PDFs it can still parse. These leaked into test output as noise. Wrap the PdfReader calls in warnings.catch_warnings() since the existing try/except already handles actual read failures. Co-Authored-By: Claude Sonnet 4.6 --- app/my_practice/utils/file_processing.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/my_practice/utils/file_processing.py b/app/my_practice/utils/file_processing.py index c704bb5..5457d60 100644 --- a/app/my_practice/utils/file_processing.py +++ b/app/my_practice/utils/file_processing.py @@ -13,6 +13,7 @@ import os import subprocess import tempfile +import warnings from pathlib import Path import pypdf @@ -64,8 +65,10 @@ def _read_page_rotations(data: bytes) -> list[int]: before compression and restore them afterwards. """ try: - reader = pypdf.PdfReader(io.BytesIO(data)) - return [int(page.get("/Rotate", 0) or 0) for page in reader.pages] + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + reader = pypdf.PdfReader(io.BytesIO(data)) + return [int(page.get("/Rotate", 0) or 0) for page in reader.pages] except Exception: return [] @@ -79,7 +82,9 @@ def _restore_page_rotations(data: bytes, rotations: list[int]) -> bytes: if not rotations or all(r == 0 for r in rotations): return data try: - reader = pypdf.PdfReader(io.BytesIO(data)) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + reader = pypdf.PdfReader(io.BytesIO(data)) writer = pypdf.PdfWriter() writer.append(reader) for i, page in enumerate(writer.pages):