Skip to content

Conversation

@andersonhc
Copy link
Collaborator

@andersonhc andersonhc commented Dec 6, 2025

This PR:

  • Adds strict typing across fpdf2, tightening method signatures, enums, and data structures so the library ships with full type info

  • Add a py.typed file that signals IDEs the fpdf2 library is typed

  • Configure strict mypy and pyright in pyproject.toml

  • Add mypy and pyright to the lint CI runner and to the pre-commit hook

The objective of this PR is to add type hinting with minimal code change otherwise.

The changes done other than typing were:

  • Move memory tracing that were used for testing only (not used by fpdf2 users) from fpdf/util.py to test/conftest.py
  • Remove the drawing debug functions from the fpdf2 library (not meant for fpdf2 users)

Checklist:

  • In case of a new feature, docstrings have been added, with also some documentation in the docs/ folder

  • A mention of the change is present in CHANGELOG.md

  • This PR is ready to be merged

By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.

@andersonhc
Copy link
Collaborator Author

Hi @Lucas-C

I’d really appreciate your thoughts on whether we should move forward with this PR.

This is a large change (strict typing across the whole codebase), but I tried to keep it as simple as possible — adding types only, without refactoring behavior.

One benefit already paid off: while typing actions.py, the checker pointed a bug in both URIAction and NamedAction classes where super() was called with next instead of next_action.

Strict typing gives us better IDE validation and helps catch issues earlier, but I’m aware it can also add verbosity and reduce some flexibility. Before we merge something this big, I’d love your perspective on whether you feel the trade-offs are worth it for the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant