Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Allow int for indirect_reference in PdfWriter.get_object #1490

Merged
merged 1 commit into from
Dec 11, 2022
Merged
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
4 changes: 3 additions & 1 deletion PyPDF2/_writer.py
Original file line number Diff line number Diff line change
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