`Document.pages()` is incorrectly type-hinted
npt opened this issue · comments
Nick Tarleton commented
Description of the bug
Document.pages()
is type-hinted as returning Page
, but actually returns a generator yielding Page
s — 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
Julian Smith commented
Fixed in 1.24.2.