Skip to content

Commit 0e4e38b

Browse files
src/ tests/: avoid exception in Page.annots() to fix #4928.
Looks like self.annot_xrefs() can return bogus xref values, which we now ignore.
1 parent b02c92f commit 0e4e38b

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10670,8 +10670,10 @@ def annots(self, types=None):
1067010670
annot_xrefs = [a[0] for a in self.annot_xrefs() if a[1] in types and a[1] not in skip_types]
1067110671
for xref in annot_xrefs:
1067210672
annot = self.load_annot(xref)
10673-
annot._yielded=True
10674-
yield annot
10673+
# In #4928, annot can be None, which we need to ignore.
10674+
if annot:
10675+
annot._yielded=True
10676+
yield annot
1067510677

1067610678
def apply_redactions(
1067710679
page: 'Page',

tests/test_general.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,13 +2213,12 @@ def test_4907():
22132213
display_list = page.get_displaylist(annots=False)
22142214
text_page = display_list.get_textpage()
22152215

2216+
22162217
def test_4928():
22172218
path = os.path.normpath(f'{__file__}/../../tests/resources/test_4928.pdf')
22182219
with pymupdf.open(path) as document:
2219-
try:
2220-
document.scrub()
2221-
except Exception as e:
2222-
print(f'Ignoring expected exception: {e}')
2220+
document.scrub()
2221+
22232222

22242223
def test_4902():
22252224
print()

0 commit comments

Comments
 (0)