-
Notifications
You must be signed in to change notification settings - Fork 1.5k
BUG: Fixed merge page bug issue with _markup_annotations objects #3577
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?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3577 +/- ##
=======================================
Coverage 97.30% 97.30%
=======================================
Files 56 56
Lines 9838 9844 +6
Branches 1790 1790
=======================================
+ Hits 9573 9579 +6
Misses 157 157
Partials 108 108 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
stefan6419846
left a comment
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.
Thanks for the PR. I have left some comments.
Additionally, could you please clarify whether this has further side effects? Does exposing the new method have the potential to break existing code? Are there any other aspects to keep in mind?
| "DictionaryObject", | ||
| self._reference_clone(self.__class__(), pdf_dest, force_duplicate), | ||
| self._reference_clone(self.__new__(self.__class__), pdf_dest, force_duplicate), | ||
| # self.__new__(self.__class__) because we want instance of type __class__, |
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.
Comments should go before, not after the code.
pypdf/_page.py
Outdated
| original_page: "PageObject" # very local use in writer when appending | ||
|
|
||
| def __new__(cls, *args: tuple[Any], **kwargs: dict[Any, Any]) -> "PageObject": | ||
| """__new__ used here to make sure instance.pdf attribute |
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.
This is an explaining comment, not a docstring, thus please make it a "simple" comment. Are we able to re-use some of the values used here in the __init__ method?
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.
what values do you mean? i would want __init__ to handle initialization of attribute because that is a python standard.
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.
The values initialized to None here.
tests/generic/test_files.py
Outdated
|
|
||
|
|
||
| def test_merge_page_with_annotation(): | ||
| # added and adapted from issue #3467 |
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.
This comment is superfluous.
i do not think it is possible to break code. a potential side effect of the change would be that the values of for other |
|
Thanks for the heads-up. Given your comment about |
i review python documentation for i will rewrite code so |
this cause side effect of double init when create object like let me reexamine |
|
@stefan6419846 i have done more reading the codebase for maybe side effects. it seems that there are more class that do not initialized instance variable also. i want to ask about |
|
Sorry, I am having some trouble to follow your comment. Could you please elaborate and reference some code and/or provide some example code showing the behavior in question? |
for key, value in vars(src).items():
if key != "indirect_reference":
setattr(self, key, value)i want to place at the end of |
|
Thanks for the explanation. Given that we iterate over all values with your proposed |
related to #3467
i notice that
_data_structures.DictionaryObject.clone()was callingself.__class__(), which looked incorrect to me. callingself.__class__()runs both__new__(cls, *args, **kwargs)and__init__(self). we are handling cloning the values ind__._clone(self)later, so we do not need to run__init__(self)constructor as we set the values of the instance using the original object.this had a side effects by breaking
PageObjectcloning, but creating the__new__(cls, *args, **kwargs)function and adding the attribute names to the instance seem to resolve it. this should not change behavior ofPageObjectinstantiation, because__init__(self)is called after__new__(cls, *args, **kwargs)