Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3052,7 +3052,14 @@ def _insert_filtered_annotations(
outlist.append(ano.clone(self).indirect_reference)
else:
d = cast("ArrayObject", d)
p = self._get_cloned_page(d[0], pages, reader)
try:
p = self._get_cloned_page(d[0], pages, reader)
except TypeError:
# There are cases where the IndirectObject is not None, but d[0] will fail:
Copy link
Collaborator

@stefan6419846 stefan6419846 Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You basically want to check for not is_null_or_none(d[0].get_object())? Having this explicitly is preferred over more costly exception handling.

# TypeError: 'NoneType' object is not subscriptable
# in generic/_base.py, in __getitem__
# at `return self._get_object_with_check()[key]`
continue
if p is not None:
anc = ano.clone(self, ignore_fields=("/D",))
cast("DictionaryObject", anc["/A"])[
Expand Down
Loading