Skip to content

Commit

Permalink
ENH: Add support for IndirectObject.__contains__ (#3155)
Browse files Browse the repository at this point in the history
Closes #3154.
  • Loading branch information
noamkush authored Mar 4, 2025
1 parent 7143554 commit 8d16885
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pypdf/generic/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ def __getitem__(self, key: Any) -> Any:
# items should be extracted from pointed Object
return self._get_object_with_check()[key] # type: ignore

def __contains__(self, key: Any) -> bool:
return key in self._get_object_with_check() # type: ignore

def __float__(self) -> str:
# in this case we are looking for the pointed data
return self.get_object().__float__() # type: ignore
Expand Down
7 changes: 7 additions & 0 deletions tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,13 @@ def test_indirect_object_page_dimensions():
assert mediabox == RectangleObject((0, 0, 792, 612))


def test_indirect_object_contains():
writer = PdfWriter()
indirect_object = IndirectObject(1, 0, writer)
assert "foo" not in indirect_object
assert "/Producer" in indirect_object


def test_array_operators():
a = ArrayObject(
[
Expand Down

0 comments on commit 8d16885

Please sign in to comment.