Skip to content

Commit

Permalink
STY: Use hasattr to determine if an object has an attribute with a gi…
Browse files Browse the repository at this point in the history
…ven name
  • Loading branch information
j-t-1 authored Jun 17, 2024
1 parent 988714f commit dd847a0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def pdf_header(self, new_header: Union[str, bytes]) -> None:

def _add_object(self, obj: PdfObject) -> IndirectObject:
if (
getattr(obj, "indirect_reference", None) is not None
hasattr(obj, "indirect_reference")
and obj.indirect_reference.pdf == self # type: ignore
):
return obj.indirect_reference # type: ignore
Expand Down Expand Up @@ -387,7 +387,7 @@ def _replace_object(
indirect_reference = indirect_reference.idnum
gen = self._objects[indirect_reference - 1].indirect_reference.generation # type: ignore
if (
getattr(obj, "indirect_reference", None) is not None
hasattr(obj, "indirect_reference")
and obj.indirect_reference.pdf != self # type: ignore
):
obj = obj.clone(self)
Expand Down

0 comments on commit dd847a0

Please sign in to comment.