From f5c3cf2d1c0177feb32f2772e8f4849cf8e50197 Mon Sep 17 00:00:00 2001 From: j-t-1 <120829237+j-t-1@users.noreply.github.com> Date: Mon, 14 Oct 2024 08:53:20 +0100 Subject: [PATCH] STY: Tiny refactor (#2901) Functions insert_blank_page and _pdf_objectify. --- pypdf/_writer.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pypdf/_writer.py b/pypdf/_writer.py index 5852e13cf..574a23054 100644 --- a/pypdf/_writer.py +++ b/pypdf/_writer.py @@ -677,7 +677,7 @@ def insert_blank_page( PageSizeNotDefinedError: if width and height are not defined and previous page does not exist. """ - if width is None or height is None and (self.get_num_pages() - 1) >= index: + if width is None or height is None and index < self.get_num_pages(): oldpage = self.pages[index] width = oldpage.mediabox.width height = oldpage.mediabox.height @@ -3244,8 +3244,6 @@ def _pdf_objectify(obj: Union[Dict[str, Any], str, int, List[Any]]) -> PdfObject casted_value = _pdf_objectify(value) to_add[name_key] = casted_value return to_add - elif isinstance(obj, list): - return ArrayObject(_pdf_objectify(el) for el in obj) elif isinstance(obj, str): if obj.startswith("/"): return NameObject(obj) @@ -3253,9 +3251,11 @@ def _pdf_objectify(obj: Union[Dict[str, Any], str, int, List[Any]]) -> PdfObject return TextStringObject(obj) elif isinstance(obj, (int, float)): return FloatObject(obj) + elif isinstance(obj, list): + return ArrayObject(_pdf_objectify(i) for i in obj) else: raise NotImplementedError( - f"type(obj)={type(obj)} could not be casted to PdfObject" + f"{type(obj)=} could not be cast to a PdfObject" )