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

MAINT: fix mypy type output #2799

Merged
merged 25 commits into from
Aug 15, 2024
Merged

MAINT: fix mypy type output #2799

merged 25 commits into from
Aug 15, 2024

Conversation

pubpub-zz
Copy link
Collaborator

closes #2798

Copy link

codecov bot commented Aug 13, 2024

Codecov Report

Attention: Patch coverage is 96.29630% with 3 lines in your changes missing coverage. Please review.

Project coverage is 95.83%. Comparing base (799630d) to head (4dd1444).
Report is 70 commits behind head on main.

Files with missing lines Patch % Lines
pypdf/_page.py 95.94% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2799      +/-   ##
==========================================
- Coverage   95.86%   95.83%   -0.03%     
==========================================
  Files          51       51              
  Lines        8528     8544      +16     
  Branches     1691     1692       +1     
==========================================
+ Hits         8175     8188      +13     
- Misses        209      212       +3     
  Partials      144      144              

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

@stefan6419846
Copy link
Collaborator

I am not completely sure about this - using private members in the public API does not feel right.

@pubpub-zz
Copy link
Collaborator Author

I am not completely sure about this - using private members in the public API does not feel right.

Can you please clarify: keys and items are public for _VirtualListImages.
if the issue is _VirtualListImages, should we rename it into VirtualListImages. this may have more impact and will make _VirtualListImages too visible without any advantage: I would not like to create a new subject of discussion such as the one we had on filters/LZWDecode

However, having a library fully compatible with mypy worth the commit

@stefan6419846
Copy link
Collaborator

In my opinion, it does not make sense to have a type hint referencing _VirtualListImages while this class is both not exposed publicly and even has a leading underscore to indicate it is private - such cases should only occur for the internal API. (ImageFile never being available as a public class is a similar issue in my opinion, but at least not prefixed by an underscore - the general issue is the same.)

@pubpub-zz pubpub-zz marked this pull request as draft August 14, 2024 06:45
@pubpub-zz pubpub-zz marked this pull request as ready for review August 14, 2024 12:26
@pubpub-zz
Copy link
Collaborator Author

Based on your comments:

  • I renamed _VirtualListImages to VirtualListImages
  • I moved ImageFile to make it public.
  • I broke the inheritance between ImageFile with File and made it obsolete(never used out of ImageFile) in order to have a standalone module
  • I also moved PIL import in _page to global in order to use (PIL.Image.)Image type

@stefan6419846
Copy link
Collaborator

I also moved PIL import in _page to global in order to use (PIL.Image.)Image type

Isn't this a breaking change for users which do not have Pillow installed?

@pubpub-zz
Copy link
Collaborator Author

I also moved PIL import in _page to global in order to use (PIL.Image.)Image type

Isn't this a breaking change for users which do not have Pillow installed?

No: the error is reported only when calling replace (as it used to be) There is no change in behavior

pypdf/_page.py Outdated Show resolved Hide resolved
pubpub-zz and others added 2 commits August 15, 2024 14:30
Co-authored-by: Stefan <96178532+stefan6419846@users.noreply.github.com>
Copy link
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.

I have reworded some of the docs.

Additionally, the ImageFile and VirtualListImages classes are still part of a private module only without being exposed in the __init__.py file. We should expose them there to allow users to actually refer to them in their own type hints if required.

pypdf/_page.py Outdated Show resolved Hide resolved
pypdf/_page.py Outdated Show resolved Hide resolved
pypdf/_page.py Outdated Show resolved Hide resolved
pypdf/_page.py Outdated Show resolved Hide resolved
pypdf/_page.py Outdated Show resolved Hide resolved
pypdf/_page.py Outdated Show resolved Hide resolved
pypdf/_utils.py Outdated Show resolved Hide resolved
pypdf/_utils.py Outdated Show resolved Hide resolved
pypdf/_utils.py Outdated Show resolved Hide resolved
tests/test_workflows.py Outdated Show resolved Hide resolved
pubpub-zz and others added 7 commits August 15, 2024 14:39
Co-authored-by: Stefan <96178532+stefan6419846@users.noreply.github.com>
Co-authored-by: Stefan <96178532+stefan6419846@users.noreply.github.com>
Co-authored-by: Stefan <96178532+stefan6419846@users.noreply.github.com>
Co-authored-by: Stefan <96178532+stefan6419846@users.noreply.github.com>
Co-authored-by: Stefan <96178532+stefan6419846@users.noreply.github.com>
Co-authored-by: Stefan <96178532+stefan6419846@users.noreply.github.com>
Co-authored-by: Stefan <96178532+stefan6419846@users.noreply.github.com>
pubpub-zz and others added 4 commits August 15, 2024 14:41
Co-authored-by: Stefan <96178532+stefan6419846@users.noreply.github.com>
Co-authored-by: Stefan <96178532+stefan6419846@users.noreply.github.com>
@pubpub-zz
Copy link
Collaborator Author

Additionally, the ImageFile and VirtualListImages classes are still part of a private module only without being exposed in the __init__.py file. We should expose them there to allow users to actually refer to them in their own type hints if required.

ImageFile and VirtualListImages are not classes that a user should create instances from : as such I see no reason for them to be part of the __init__.py

The objective is just to fix mypy and the test report in the issue was positive

@stefan6419846
Copy link
Collaborator

Okay, let's keep this for now - except for the other remark regarding finally which still should be fixed.

@stefan6419846 stefan6419846 merged commit 454a62a into py-pdf:main Aug 15, 2024
16 checks passed
@pubpub-zz pubpub-zz mentioned this pull request Sep 15, 2024
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.

Type hint for page.images needs adjusting
2 participants