Skip to content

Commit f5c3cf2

Browse files
authored
STY: Tiny refactor (#2901)
Functions insert_blank_page and _pdf_objectify.
1 parent c9dda9a commit f5c3cf2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pypdf/_writer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ def insert_blank_page(
677677
PageSizeNotDefinedError: if width and height are not defined
678678
and previous page does not exist.
679679
"""
680-
if width is None or height is None and (self.get_num_pages() - 1) >= index:
680+
if width is None or height is None and index < self.get_num_pages():
681681
oldpage = self.pages[index]
682682
width = oldpage.mediabox.width
683683
height = oldpage.mediabox.height
@@ -3244,18 +3244,18 @@ def _pdf_objectify(obj: Union[Dict[str, Any], str, int, List[Any]]) -> PdfObject
32443244
casted_value = _pdf_objectify(value)
32453245
to_add[name_key] = casted_value
32463246
return to_add
3247-
elif isinstance(obj, list):
3248-
return ArrayObject(_pdf_objectify(el) for el in obj)
32493247
elif isinstance(obj, str):
32503248
if obj.startswith("/"):
32513249
return NameObject(obj)
32523250
else:
32533251
return TextStringObject(obj)
32543252
elif isinstance(obj, (int, float)):
32553253
return FloatObject(obj)
3254+
elif isinstance(obj, list):
3255+
return ArrayObject(_pdf_objectify(i) for i in obj)
32563256
else:
32573257
raise NotImplementedError(
3258-
f"type(obj)={type(obj)} could not be casted to PdfObject"
3258+
f"{type(obj)=} could not be cast to a PdfObject"
32593259
)
32603260

32613261

0 commit comments

Comments
 (0)