Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the Python type annotations for fitz_new #2883

Open
indigoviolet opened this issue Dec 12, 2023 · 3 comments
Open

Improve the Python type annotations for fitz_new #2883

indigoviolet opened this issue Dec 12, 2023 · 3 comments
Labels
enhancement postpone postpone to a future version

Comments

@indigoviolet
Copy link

Is your feature request related to a problem? Please describe.

Python type hints (which can be validated using mypy or Pylance in vscode) are very helpful; fitz_new has much better coverage than fitz in this regard. However several methods are dynamically assigned (eg. Page.get_text is assigned from utils.get_text). These types are not visible to the typechecker.

Describe the solution you'd like
Use a type stub file to describe the type signatures of these functions so that typecheckers can see them, and include the typestub in PEP 484/561 - compliant fashion.

Thank you!

@indigoviolet
Copy link
Author

Alternatively, instead of the dynamic assignment, use some kind of mixin class, or make the utils functions the dynamically assigned ones (since the docs all refer to the Page/Document class methods)

@julian-smith-artifex-com
Copy link
Collaborator

We are looking at possible architectural changes that will allow better type hints in future. But it's quite an involved process so there are no timescales at the moment.

@JorjMcKie
Copy link
Collaborator

For the time being, change your import statement(s) to import pymupdf as fitz if you even need the deprecated name fitz.

This should let you benefit from PyMuPDF's improvements in this area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement postpone postpone to a future version
Projects
None yet
Development

No branches or pull requests

3 participants