-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
base: main
Are you sure you want to change the base?
STY: Tweak PdfWriter #3337
Conversation
Small changes including making method insert_blank_page more flexible.
Small changes including making method insert_blank_page more flexible.
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. 🚀 New features to boost your workflow:
|
Could you please have a look at the coverage? All (new) conditions should be covered be appropriate tests. |
@@ -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(): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>
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 |
There was a problem hiding this comment.
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.
Small changes including making method insert_blank_page more flexible.