Skip to content

Commit

Permalink
ENH: Allow int for indirect_reference in PdfWriter.get_object
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Dec 11, 2022
1 parent 437aec9 commit 6d96232
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion PyPDF2/_writer.py
Expand Up @@ -204,7 +204,7 @@ def _add_object(self, obj: PdfObject) -> IndirectObject:

def get_object(
self,
indirect_reference: Optional[IndirectObject] = None,
indirect_reference: Union[None, int, IndirectObject] = None,
ido: Optional[IndirectObject] = None,
) -> PdfObject:
if ido is not None: # deprecated
Expand All @@ -221,6 +221,8 @@ def get_object(
assert (
indirect_reference is not None
) # the None value is only there to keep the deprecated name
if isinstance(indirect_reference, int):
return self._objects[indirect_reference - 1]
if indirect_reference.pdf != self:
raise ValueError("pdf must be self")
return self._objects[indirect_reference.idnum - 1] # type: ignore
Expand Down

0 comments on commit 6d96232

Please sign in to comment.