From 6d2d25f972ceede355afe133c410a87c4308312f Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Tue, 12 Jul 2022 07:47:11 +0200 Subject: [PATCH] MAINT: Use add_bookmark_destination in add_bookmark_dict (#1099) Re-use code See #1098 --- PyPDF2/_writer.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/PyPDF2/_writer.py b/PyPDF2/_writer.py index bde7d15e65..463aad7645 100644 --- a/PyPDF2/_writer.py +++ b/PyPDF2/_writer.py @@ -1055,7 +1055,7 @@ def getNamedDestRoot(self) -> ArrayObject: # pragma: no cover return self.get_named_dest_root() def add_bookmark_destination( - self, dest: PageObject, parent: Optional[TreeObject] = None + self, dest: Union[PageObject, TreeObject], parent: Optional[TreeObject] = None ) -> IndirectObject: dest_ref = self._add_object(dest) @@ -1096,18 +1096,7 @@ def add_bookmark_dict( action_ref = self._add_object(action) bookmark_obj[NameObject("/A")] = action_ref - bookmark_ref = self._add_object(bookmark_obj) - - outline_ref = self.get_outline_root() - - if parent is None: - parent = outline_ref - - parent = parent.get_object() # type: ignore - assert parent is not None, "hint for mypy" - parent.add_child(bookmark_ref, self) - - return bookmark_ref + return self.add_bookmark_destination(bookmark_obj, parent) def addBookmarkDict( self, bookmark: BookmarkTypes, parent: Optional[TreeObject] = None