Skip to content

ENH: Add actions base class#3552

Draft
j-t-1 wants to merge 45 commits intopy-pdf:mainfrom
j-t-1:actions
Draft

ENH: Add actions base class#3552
j-t-1 wants to merge 45 commits intopy-pdf:mainfrom
j-t-1:actions

Conversation

@j-t-1
Copy link
Copy Markdown
Contributor

@j-t-1 j-t-1 commented Dec 6, 2025

Implement the JavaScript action at page-level.

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.38%. Comparing base (0e9792d) to head (0894957).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3552      +/-   ##
==========================================
+ Coverage   97.36%   97.38%   +0.01%     
==========================================
  Files          55       57       +2     
  Lines        9942    10001      +59     
  Branches     1823     1836      +13     
==========================================
+ Hits         9680     9739      +59     
  Misses        152      152              
  Partials      110      110              

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

@j-t-1 j-t-1 marked this pull request as draft December 7, 2025 08:37
@j-t-1 j-t-1 marked this pull request as ready for review January 1, 2026 16:18
@stefan6419846 stefan6419846 added the needs-change The PR/issue cannot be handled as issue and needs to be improved label Jan 9, 2026
@j-t-1
Copy link
Copy Markdown
Contributor Author

j-t-1 commented Feb 17, 2026

@stefan6419846 ready for code review. The code coverage is picking up comments, I don't know if this is a real code coverage issue or not.

@stefan6419846
Copy link
Copy Markdown
Collaborator

Could you please have a look at the style failures and the coverage first?

@j-t-1
Copy link
Copy Markdown
Contributor Author

j-t-1 commented Feb 17, 2026

Could you please have a look at the style failures and the coverage first?

Yes will try and fix the style failures.

The coverage seems ok, and is even hightlighting comments.

@stefan6419846
Copy link
Copy Markdown
Collaborator

The coverage seems ok, and is even hightlighting comments.

Invalid trigger values are not covered correctly. Additionally, rebasing the code on the lastest main might help as the comment indicates that your branch is 42 commits behind, possibly leading to unexpected results.

Comment thread pypdf/_page.py
Comment thread pypdf/actions/__init__.py Outdated
Comment thread pypdf/_page.py
# Example: Display the page number when the page is closed
>>> self.add_action("close", JavaScript("app.alert('This is page ' + this.pageNum);")))
"""
if trigger not in {"open", "close"}:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please avoid such large implementations inside the PageObject it possible. I guess we could make the internals of add_action a private method of the Action class and the internals of delete_action a private class method of the `Action class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Although it is a large addition, the design as driven by you in an earlier Issue is good. Once all the other action types are added, that adds a lot of code, but this will be outside of PageObject and also in its own test file (test_actions.py).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The design defined the basic API, not the whole implementation. Thus I still propose to move the actual internal implementation out of the _page.py file and call it accordingly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@stefan6419846 I will take your advice that this is the best way for this and implement it. Is there an existing function where we do this, or you can provide a method prototype so I can understand the idea?

Also could you help get the other PR (make any changes you want) done so I can concentrate on this PR?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is there an existing function where we do this

See pypdf._writer.PdfWriter.add_attachment.

Also could you help get the other PR (make any changes you want) done so I can concentrate on this PR?

My personal resources are limited, thus I generally try to avoid doing larger changes to PRs not created by me. Exceptions might be critical fixes. I suggest you to mark your PR as draft while you are not working on it to come back to it later, although my usual recommendation would be to wait for one change to be successfully merged before getting started with the next one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

After addding an Actions interface in this PR, I may add it to other objects. So function overloading will be needed.

For the other one it is ready to merge now and passes the tests. I agree about doing one PR at a time, and will mark this one as draft, as the other one is nearly a year old.

Comment thread tests/test_actions.py Outdated
Comment thread pypdf/_page.py Outdated
@j-t-1 j-t-1 marked this pull request as draft April 17, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-change The PR/issue cannot be handled as issue and needs to be improved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants