Skip to content

Implement strict type hinting#1691

Merged
andersonhc merged 7 commits intopy-pdf:masterfrom
andersonhc:typing
Jan 8, 2026
Merged

Implement strict type hinting#1691
andersonhc merged 7 commits intopy-pdf:masterfrom
andersonhc:typing

Conversation

@andersonhc
Copy link
Copy Markdown
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
Copy Markdown
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.

@andersonhc andersonhc merged commit db21301 into py-pdf:master Jan 8, 2026
23 checks passed
@Lucas-C
Copy link
Copy Markdown
Member

Lucas-C commented Jan 10, 2026

Hi @andersonhc

Sorry for my lack of answer regarding this...

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.

You did well in merging this, this is a really nice addition to fpdf2, and I think the advantages outweigh the disadvantages.

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.

2 participants