Skip to content

TST: Extending typing to tests; cover generic and scripts folder files#3660

Merged
stefan6419846 merged 22 commits intopy-pdf:mainfrom
iso-techdev:issue-3591-PR-1
Apr 7, 2026
Merged

TST: Extending typing to tests; cover generic and scripts folder files#3660
stefan6419846 merged 22 commits intopy-pdf:mainfrom
iso-techdev:issue-3591-PR-1

Conversation

@iso-techdev
Copy link
Copy Markdown
Contributor

@iso-techdev iso-techdev commented Feb 26, 2026

  • mypy --version: mypy 1.17.0 (compiled: yes)
  • python3 --version: Python 3.12.3
  • python3 -m platform: Linux-6.8.0-94-generic-x86_64-with-glibc2.39

command:
(.venv) python@issam:~/Desktop/github_repositories/Open-Source/Forked-pypdf/pypdf/tests$ mypy --package generic --package scripts
Success: no issues found in 9 source files

This fixes #3591

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.43%. Comparing base (bd95bd8) to head (86b9c82).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3660   +/-   ##
=======================================
  Coverage   97.43%   97.43%           
=======================================
  Files          55       55           
  Lines       10022    10022           
  Branches     1842     1842           
=======================================
  Hits         9765     9765           
  Misses        149      149           
  Partials      108      108           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@iso-techdev iso-techdev changed the title #3591: Extending typing to tests; cover generic and scripts folder files TST: Extending typing to tests; cover generic and scripts folder files Feb 26, 2026
Copy link
Copy Markdown
Collaborator

@stefan6419846 stefan6419846 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the configuration to run proper linting in the CI for these files.

Additionally, running the type checker for files which are not guaranteed to have type hints at all does not sound correct as well. These should ideally be included into the type checks before getting started with the testing PR.

Comment thread tests/generic/test_files.py Outdated
@iso-techdev
Copy link
Copy Markdown
Contributor Author

iso-techdev commented Mar 9, 2026

Sorry for coming back late. You said: "Please update the configuration to run proper linting in the CI for these files." I used ruff from the configuration files in the command line, but I fear that's not what you wanted exactly. Therefore can you please elaborate on what you mean by updating the configuration to run proper linting in the ci for these files.

Also you said: Additionally, running the type checker for files which are not guaranteed to have type hints at all does not sound correct as well. These should ideally be included into the type checks before getting started with the testing PR.

Can you also explain this a little bit more or give some examples or hints on which files you are talking about. That would be very much appreciated.

@stefan6419846

@stefan6419846
Copy link
Copy Markdown
Collaborator

I used ruff from the configuration files in the command line, but I fear that's not what you wanted exactly.

Yes, because we want to automatically run this in CI, not only locally. Additionally, I guess you meant mypy as in the original comment, as ruff is the style checker, not the type checker.

Therefore can you please elaborate on what you mean by updating the configuration to run proper linting in the ci for these files.

The mypy configuration needs to be updated to reflect these changes, id est not exclude the migrated files any more. This most likely means updating the corresponding pyproject.toml sections.

Additionally, in the workflow file for the typing tests, we currently run mypy pypdf only. This needs to be updated to cover all correct files which are not explicitly excluded by the corresponding configuration section.

Also you said: Additionally, running the type checker for files which are not guaranteed to have type hints at all does not sound correct as well. These should ideally be included into the type checks before getting started with the testing PR.
Can you also explain this a little bit more or give some examples or hints on which files you are talking about. That would be very much appreciated.

In the pyproject.toml file, we explicitly exclude make_release.py from the usual type checks. Enabling type checks for the tests should enable them for the script itself as well to make sure that we do not miss anything.

@iso-techdev
Copy link
Copy Markdown
Contributor Author

I understand, however shouldn't this be at the last pr. This pr is only covering a small portion of the tests, in the last pr when i finish all the tests then we can include the tests folder in the configuration. Do you want me to include only the folders that i finished (for example tests/generic tests/scripts).

@stefan6419846
Copy link
Copy Markdown
Collaborator

No, because I do not want to have to remember which parts have been migrated manually and ideally want to be able to check in CI that everything is correct.

@iso-techdev
Copy link
Copy Markdown
Contributor Author

Solutions:

1- I finish all the tests and add the tests folder into the configuration and ci in one pr which is this one.

or

2- If we have to split all the tests into several prs then we can't add the whole tests folder into the ci from the first pr since it will fail. Then we either can add the parts that are finished or ignore it till the last pr.

Your suggestions are much appreciated.

@stefan6419846
Copy link
Copy Markdown
Collaborator

We should add files to the configuration as soon as we attempted the migration/fix.

Comment thread pypdf/generic/_image_xobject.py Outdated
Comment thread tests/generic/test_data_structures.py
Comment thread tests/generic/test_data_structures.py Outdated
Comment thread tests/generic/test_files.py Outdated
Comment thread tests/generic/test_files.py Outdated
Comment thread tests/generic/test_files.py
Comment thread tests/generic/test_files.py Outdated
Comment thread tests/generic/test_files.py Outdated
Comment thread tests/generic/test_image_inline.py Outdated
Comment thread .github/workflows/github-ci.yaml Outdated
Comment thread tests/generic/test_base.py Outdated
Comment thread tests/scripts/test_make_release.py
Comment thread tests/utils.py Outdated
@iso-techdev
Copy link
Copy Markdown
Contributor Author

iso-techdev commented Mar 19, 2026

Fixed the inline comments, I am not sure if i missed any of the inline comments you added. I also fixed the failing ci.
I added the missing yaml stub in the requirements file and regenerated them using the pip-compile as commented.
Now mypy also runs in the ci checking the test folders i finished.

I reverted the changes done by the black formatter manually hopefully didn't miss any.
Thank you for all the feedback.

Comment thread requirements/ci.in Outdated
Comment thread requirements/ci.txt Outdated
Comment thread tests/generic/test_data_structures.py Outdated
Comment thread tests/generic/test_data_structures.py Outdated
Comment thread tests/generic/test_data_structures.py Outdated
Comment thread tests/generic/test_image_xobject.py Outdated
Comment thread tests/generic/test_image_xobject.py Outdated
Comment thread tests/scripts/test_make_release.py Outdated
Comment thread tests/scripts/test_make_release.py Outdated
Comment thread tests/scripts/test_make_release.py
Comment thread tests/generic/test_image_xobject.py Outdated
Comment thread pyproject.toml
Comment thread requirements/ci.txt Outdated
Comment thread tests/generic/test_files.py Outdated
Comment thread tests/generic/test_image_xobject.py Outdated
Comment thread tests/__init__.py Outdated
Comment thread .github/workflows/github-ci.yaml Outdated
Comment thread pyproject.toml
@iso-techdev
Copy link
Copy Markdown
Contributor Author

@stefan6419846 Hope you are doing well, thank you for the help in this pr.
Is there anything i need to fix?

@stefan6419846
Copy link
Copy Markdown
Collaborator

I am currently on vacation and thus reviews are mostly delayed, hoping that I find enough time next week.

Comment thread tests/generic/test_image_xobject.py Outdated
Copy link
Copy Markdown
Collaborator

@stefan6419846 stefan6419846 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patience.

@stefan6419846 stefan6419846 merged commit 5456731 into py-pdf:main Apr 7, 2026
24 of 30 checks passed
@iso-techdev
Copy link
Copy Markdown
Contributor Author

Thank you for the guidance and the patience.

costajohnt added a commit to costajohnt/pypdf that referenced this pull request Apr 9, 2026
Replace individual mypy flags with `strict = true` in pyproject.toml and
fix all resulting type errors across the codebase.

Changes:
- pyproject.toml: use `strict = true`, keep test overrides from py-pdf#3660
- .pre-commit-config.yaml: add cryptography and pycryptodome as
  additional_dependencies for mypy hook
- Makefile: simplify mypy target (config now in pyproject.toml)
- Fix type annotations in ~20 source files
- Fix latent bug: `data[-1] != b"\n"` compared int to bytes (always True),
  changed to `data[-1:] != b"\n"` for correct bytes comparison
- Add tests for AnnotationDictionary.flags, Destination defaults,
  ArrayObject._to_lst
@iso-techdev iso-techdev deleted the issue-3591-PR-1 branch April 10, 2026 07:53
costajohnt added a commit to costajohnt/pypdf that referenced this pull request Apr 14, 2026
Replace individual mypy flags with `strict = true` in pyproject.toml and
fix all resulting type errors across the codebase.

Changes:
- pyproject.toml: use `strict = true`, keep test overrides from py-pdf#3660
- .pre-commit-config.yaml: add cryptography and pycryptodome as
  additional_dependencies for mypy hook
- Makefile: simplify mypy target (config now in pyproject.toml)
- Fix type annotations in ~20 source files
- Fix latent bug: `data[-1] != b"\n"` compared int to bytes (always True),
  changed to `data[-1:] != b"\n"` for correct bytes comparison
- Add tests for AnnotationDictionary.flags, Destination defaults,
  ArrayObject._to_lst
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.

Use placeholder-based approach for logger_error and logger_warning

2 participants