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

BUG: Don't close stream passed to PdfWriter.write() #2909

Merged
merged 12 commits into from
Oct 30, 2024

Conversation

alexaryn
Copy link
Contributor

Closes #2905

Copy link

codecov bot commented Oct 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.39%. Comparing base (9e0fce7) to head (c46072d).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2909   +/-   ##
=======================================
  Coverage   96.39%   96.39%           
=======================================
  Files          52       52           
  Lines        8730     8741   +11     
  Branches     1590     1590           
=======================================
+ Hits         8415     8426   +11     
  Misses        186      186           
  Partials      129      129           

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

pypdf/_writer.py Outdated Show resolved Hide resolved
pypdf/_writer.py Show resolved Hide resolved
tests/test_writer.py Show resolved Hide resolved
pypdf/_writer.py Outdated Show resolved Hide resolved
@pubpub-zz
Copy link
Collaborator

I've created PR #2913 that also deals with Context manager. Consistency should be checked

tests/test_writer.py Outdated Show resolved Hide resolved
@alexaryn
Copy link
Contributor Author

@stefan6419846 let me know how you'd like to proceed

pypdf/_writer.py Outdated Show resolved Hide resolved
@stefan6419846
Copy link
Collaborator

While I doubt that many users really rely on it, the deprecation process mentioned in https://github.com/py-pdf/pypdf/pull/2909/files#r1808253593 is still necessary as we are replacing a public attribute.

@alexaryn
Copy link
Contributor Author

The Windows CI test looks like a spurious failure due to a file missing from cache. I'm not sure what to do with the test coverage issues, as the lines cited are after the deprecation logic.

@stefan6419846
Copy link
Collaborator

Do not worry about the Windows CI - we will have a look at this. Windows does not use the cache for different reasons, but we are currently evaluating alternatives to the usually failing arXiv downloads while avoiding copyright issues.

For the coverage, we tend to have a corresponding test which ensures the deprecation message being issued correctly (at least for past deprecations). This should work here as well by trying to read and write the value in one dedicated test function and looking into caplog.

@alexaryn
Copy link
Contributor Author

@stefan6419846 I tried to rely on caplog alone, but the presence of the warning seemed to fail the test. So, I used pytest.warns() which allows me to validate the message and keeps the test from failing. For some reason, the deprecation message does not end up in the caplog; so, I'm not checking it.

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.

Thanks. Looks good for me.

@stefan6419846 stefan6419846 merged commit 98aa974 into py-pdf:main Oct 30, 2024
16 checks passed
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.

PdfWriter.write() in context manager closes stream when it should not
3 participants