Skip to content

Document.pages() is incorrectly type-hinted #3331

@npt

Description

@npt

Description of the bug

Document.pages() is type-hinted as returning Page, but actually returns a generator yielding Pages — it should be hinted as returning Iterator[Page].

How to reproduce the bug

With this saved in repro.pdf:

import fitz
pdf = fitz.open('foo.pdf')
for page in pdf.pages():
    print(page)
print('success')

pyright complains:

$ pyright repro.py 
/home/nick/code/hca/health/src/pdf_rotator/repro.py
  /home/nick/code/hca/health/src/pdf_rotator/repro.py:3:13 - error: "Page" is not iterable
    "__iter__" method not defined (reportGeneralTypeIssues)
1 error, 0 warnings, 0 informations 

but the code runs (with foo.pdf present):

$ python repro.py 
page 0 of foo.pdf
success

PyMuPDF version

1.24.0

Operating system

Linux

Python version

3.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions