pymupdf / PyMuPDF

PyMuPDF is a high performance Python library for data extraction, analysis, conversion & manipulation of PDF (and other) documents.

Home Page:https://pymupdf.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Document.pages()` is incorrectly type-hinted

npt opened this issue · comments

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

Fixed in 1.24.2.