PyMuPDF
PyMuPDF copied to clipboard
Document.delete_pages declines keyword arguments
Describe the bug
When using Document.delete_pages with keyword-only arguments (as documented in Format 1), an error is reported:
Traceback (most recent call last):
File "/home/me/path/to/file.py", line 7, in <module>
document.delete_pages(from_page=1, to_page=document.page_count)
File "/home/me/lib/python3.6/site-packages/fitz/fitz.py", line 5286, in delete_pages
raise ValueError("cannot mix keyword and positional argument")
ValueError: cannot mix keyword and positional argument
Adding some debugging to the offending section, it seems like PyMuPDF assumes that *args will always be a list, but usually is a tuple:
args = ()
kw = {'from_page': 1, 'to_page': 1}
To Reproduce
import fitz
print(fitz.version)
document = fitz.Document('/home/me/path/to/document.pdf')
print(document.page_count)
document.delete_pages(from_page=1, to_page=document.page_count)
print(document.page_count)
Expected behavior
No error is raised.
Your configuration
- OpenSUSE Leap 15.3, 64 bit
- Python 3.6
- PyMuPDF 1.19.6 and 1.20.1, generated from source
Accepted - will be fixed in next version. Thanks for the report.
Fixed in 1.21.0