Skip to content

Commit 8d16885

Browse files
authored
ENH: Add support for IndirectObject.__contains__ (#3155)
Closes #3154.
1 parent 7143554 commit 8d16885

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pypdf/generic/_base.py

+3
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ def __getitem__(self, key: Any) -> Any:
392392
# items should be extracted from pointed Object
393393
return self._get_object_with_check()[key] # type: ignore
394394

395+
def __contains__(self, key: Any) -> bool:
396+
return key in self._get_object_with_check() # type: ignore
397+
395398
def __float__(self) -> str:
396399
# in this case we are looking for the pointed data
397400
return self.get_object().__float__() # type: ignore

tests/test_generic.py

+7
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,13 @@ def test_indirect_object_page_dimensions():
10321032
assert mediabox == RectangleObject((0, 0, 792, 612))
10331033

10341034

1035+
def test_indirect_object_contains():
1036+
writer = PdfWriter()
1037+
indirect_object = IndirectObject(1, 0, writer)
1038+
assert "foo" not in indirect_object
1039+
assert "/Producer" in indirect_object
1040+
1041+
10351042
def test_array_operators():
10361043
a = ArrayObject(
10371044
[

0 commit comments

Comments
 (0)