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

DEV: Unify mypy options and warn redundant workarounds #2223

Merged
merged 4 commits into from
Oct 7, 2023

Conversation

exiledkingcc
Copy link
Contributor

No description provided.

@codecov
Copy link

codecov bot commented Oct 1, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (30db3ef) 94.36% compared to head (a316621) 94.36%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2223      +/-   ##
==========================================
- Coverage   94.36%   94.36%   -0.01%     
==========================================
  Files          43       43              
  Lines        7591     7589       -2     
  Branches     1498     1497       -1     
==========================================
- Hits         7163     7161       -2     
  Misses        264      264              
  Partials      164      164              
Files Coverage Δ
pypdf/_crypt_providers/_cryptography.py 100.00% <100.00%> (ø)
pypdf/_crypt_providers/_fallback.py 95.34% <100.00%> (ø)
pypdf/_crypt_providers/_pycryptodome.py 100.00% <100.00%> (ø)
pypdf/_encryption.py 95.84% <100.00%> (ø)
pypdf/_merger.py 100.00% <100.00%> (ø)
pypdf/_page.py 94.35% <100.00%> (-0.01%) ⬇️
pypdf/_protocols.py 100.00% <100.00%> (ø)
pypdf/_reader.py 91.69% <100.00%> (ø)
pypdf/_utils.py 98.58% <100.00%> (ø)
pypdf/_writer.py 88.34% <100.00%> (-0.01%) ⬇️
... and 6 more

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

Comment on lines +129 to +131
- name: Test with mypy
run : |
mypy pypdf
Copy link
Member

Choose a reason for hiding this comment

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

Does mypy behave the same for different Python versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i simply checked py3.8 ~ py3.11, they behaved the same. but for py3.6, probably it's not.

Copy link
Member

Choose a reason for hiding this comment

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

Lets see if I get good answers for this via https://stackoverflow.com/q/77219925/562769

I suspect that it should give the same results, so I tend to agree with this change.

@MartinThoma MartinThoma changed the title unify mypy options and warn redundant workarounds DEV: Unify mypy options and warn redundant workarounds Oct 3, 2023
@MartinThoma MartinThoma merged commit dfb3c03 into py-pdf:main Oct 7, 2023
11 of 12 checks passed
@MartinThoma
Copy link
Member

Thank you very much for the cleanup 🙏

@MartinThoma
Copy link
Member

Running mypy for Python 3.10 I now get:

pypdf/_protocols.py:10: error: Unused "type: ignore" comment
pypdf/_protocols.py:10: error: Incompatible import of "Protocol" (imported name has type "typing_extensions._SpecialForm", local name has type "typing._SpecialForm")  [misc]
pypdf/_protocols.py:10: note: Error code "misc" not covered by "type: ignore" comment
pypdf/types.py:9: error: Unused "type: ignore" comment
pypdf/types.py:9: error: Incompatible import of "Literal" (imported name has type "typing_extensions._SpecialForm", local name has type "typing._SpecialForm")  [misc]
pypdf/types.py:9: note: Error code "misc" not covered by "type: ignore" comment
pypdf/_xobj_image_helpers.py:22: error: Unused "type: ignore" comment
pypdf/_xobj_image_helpers.py:22: error: Incompatible import of "Literal" (imported name has type "typing_extensions._SpecialForm", local name has type "typing._SpecialForm")  [misc]
pypdf/_xobj_image_helpers.py:22: note: Error code "misc" not covered by "type: ignore" comment
pypdf/_reader.py:323: error: Item "str" of "Union[Union[str, IO[Any]], Path]" has no attribute "mode"  [union-attr]
pypdf/_reader.py:323: error: Item "Path" of "Union[Union[str, IO[Any]], Path]" has no attribute "mode"  [union-attr]
pypdf/_reader.py:[13](https://github.com/py-pdf/pypdf/actions/runs/6439903154/job/17488260473?pr=2242#step:17:14)61: error: Item "IO[Any]" of "Union[BytesIO, IO[Any]]" has no attribute "getbuffer"  [union-attr]
pypdf/_reader.py:[14](https://github.com/py-pdf/pypdf/actions/runs/6439903154/job/17488260473?pr=2242#step:17:15)[15](https://github.com/py-pdf/pypdf/actions/runs/6439903154/job/17488260473?pr=2242#step:17:16): error: Item "IO[Any]" of "Union[BytesIO, IO[Any]]" has no attribute "getbuffer"  [union-attr]
pypdf/_reader.py:[17](https://github.com/py-pdf/pypdf/actions/runs/6439903154/job/17488260473?pr=2242#step:17:18)08: error: "IO[Any]" has no attribute "getbuffer"  [attr-defined]
pypdf/_writer.py:2[20](https://github.com/py-pdf/pypdf/actions/runs/6439903154/job/17488260473?pr=2242#step:17:21)8: error: Argument 1 has incompatible type "Iterable[ObjectDeletionFlag]"; expected "int"  [arg-type]
pypdf/_writer.py:2208: note: Left operand is of type "Union[ObjectDeletionFlag, Iterable[ObjectDeletionFlag]]"
pypdf/_writer.py:2[21](https://github.com/py-pdf/pypdf/actions/runs/6439903154/job/17488260473?pr=2242#step:17:22)0: error: Argument 1 has incompatible type "Iterable[ObjectDeletionFlag]"; expected "int"  [arg-type]
pypdf/_writer.py:[22](https://github.com/py-pdf/pypdf/actions/runs/6439903154/job/17488260473?pr=2242#step:17:23)10: note: Left operand is of type "Union[ObjectDeletionFlag, Iterable[ObjectDeletionFlag]]"
pypdf/_writer.py:2[23](https://github.com/py-pdf/pypdf/actions/runs/6439903154/job/17488260473?pr=2242#step:17:24)7: error: Argument 1 has incompatible type "Iterable[ObjectDeletionFlag]"; expected "int"  [arg-type]
pypdf/_writer.py:2237: note: Left operand is of type "Union[ObjectDeletionFlag, Iterable[ObjectDeletionFlag]]"
Found 14 errors in 5 files (checked 43 source files)
Error: Process completed with exit code 1.

I wonder if that has an effect on code using pypdf. If it has, we need to fix it.

@MartinThoma
Copy link
Member

I'll leave it like that for the moment as your change made the code a lot easier to read. However, if the CI of users fails due to that I'll revert many of the changes.

MartinThoma added a commit that referenced this pull request Oct 8, 2023
## What's new

### Bug Fixes (BUG)
-  invalid cm/tm in visitor functions (#2206) by @pubpub-zz
-  Encrypt / decrypt Stream object dictionaries (#2228) by @pilotandy
-  Support nested color spaces for the /DeviceN color space (#2241) by @Stefan
-  images property fails if NullObject in list (#2215) by @pubpub-zz

### Robustness (ROB)
-  XYZ destination to cope with missing left and top param (#2237) by @pubpub-zz

### Documentation (DOC)
-  Add pilotandy for #2228 as a contributor by @MartinThoma
-  Link to CONTRIBUTING.md in README.md (#2232) by @markpfeifle
-  Changelog by @MartinThoma

### Developer Experience (DEV)
-  Exclude tests from mypy checks by @MartinThoma
-  Unify mypy options and warn redundant workarounds (#2223) by @exiledkingcc
-  Stabilize Pillow test with Pillow missing (#2229) by @Stefan

### Maintenance (MAINT)
-  Update pinned packages (#2243) by @MartinThoma

### Testing (TST)
-  Regression test against non-deterministic accidental object reuse (#2244) by @MartinThoma

[Full Changelog](3.16.2...3.16.3)
@exiledkingcc exiledkingcc deleted the clean branch October 16, 2023 02:47
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