Skip to content

Commit 7f7fd95

Browse files
ENH: Add support for IndirectObject.__iter__ (#3228)
Closes #3227.
1 parent 2c19420 commit 7f7fd95

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pypdf/generic/_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ def __getitem__(self, key: Any) -> Any:
393393
def __contains__(self, key: Any) -> bool:
394394
return key in self._get_object_with_check() # type: ignore
395395

396+
def __iter__(self) -> Any:
397+
return self._get_object_with_check().__iter__() # type: ignore
398+
396399
def __float__(self) -> str:
397400
# in this case we are looking for the pointed data
398401
return self.get_object().__float__() # type: ignore

tests/test_generic.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,13 @@ def test_indirect_object_contains():
10391039
assert "/Producer" in indirect_object
10401040

10411041

1042+
def test_indirect_object_iter():
1043+
writer = PdfWriter()
1044+
indirect_object = IndirectObject(1, 0, writer)
1045+
assert "foo" not in list(indirect_object)
1046+
assert "/Producer" in list(indirect_object)
1047+
1048+
10421049
def test_array_operators():
10431050
a = ArrayObject(
10441051
[

0 commit comments

Comments
 (0)