Skip to content

STY: Tweak PdfWriter #3337

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

STY: Tweak PdfWriter #3337

wants to merge 6 commits into from

Conversation

j-t-1
Copy link
Contributor

@j-t-1 j-t-1 commented Jun 28, 2025

Small changes including making method insert_blank_page more flexible.

j-t-1 added 2 commits June 28, 2025 08:54
Small changes including making method insert_blank_page more flexible.
Small changes including making method insert_blank_page more flexible.
Copy link

codecov bot commented Jun 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@ed645ca). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3337   +/-   ##
=======================================
  Coverage        ?   96.73%           
=======================================
  Files           ?       53           
  Lines           ?     9062           
  Branches        ?     1678           
=======================================
  Hits            ?     8766           
  Misses          ?      177           
  Partials        ?      119           

☔ 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.

@stefan6419846
Copy link
Collaborator

Could you please have a look at the coverage? All (new) conditions should be covered be appropriate tests.

@stefan6419846 stefan6419846 added the needs-test A test should be added before this PR is merged. label Jun 28, 2025
@@ -672,10 +671,12 @@ def insert_blank_page(
and previous page does not exist.

"""
if width is None or (height is None and index < self.get_num_pages()):
if (width is None or height is None) and index < self.get_num_pages():
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't this change when this is executed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Functionality is changed. If width is None we only want to branch if index < self.get_num_pages().

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please elaborate why? Has this been a bug we need to fix or are there other reasons?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

width and height are kinda symmetric, I do not think they should be handled differently. It is slightly confusing they are handled differently. So this changes this, and also stops branching when width is None and index >= self.get_num_pages().

Co-authored-by: Stefan <96178532+stefan6419846@users.noreply.github.com>
j-t-1 added 3 commits June 28, 2025 12:37
Small changes including making method insert_blank_page more flexible.
Small changes including making method insert_blank_page more flexible.
Small changes including making method insert_blank_page more flexible.
@@ -236,6 +236,10 @@ def writer_operate(writer: PdfWriter) -> None:
writer.page_mode = NameObject("/UseOC")
assert writer._get_page_mode() == "/UseOC"
writer.insert_blank_page(width=100, height=100)
page = writer.insert_blank_page(width=100)
assert page.mediabox.height == 100
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use a dedicated test method for this and add assertions for the width and height respectively as well to ensure that it is indeed working correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-test A test should be added before this PR is merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants