-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
MAINT: Use consistent method keywords #1187
Comments
Wow, amazing work! 😮 Thank you so much 👏👏🤗 I completely agree with your concluding remarks! |
I would completely ignore already deprecated functions / parameters. Think of them as no longer being present in the library. You're seeing a ghost of the past there :-) |
I have another one: Instead of |
Agree, |
This PR ensures PyPDF2 uses page_number instead of pagenum as a parameter name. * It does not touch functions that are deprecated anyway. * The position of the new parameter is the same as the old one * The old parameter name is added to ensure that people who use the keyword-parameter don't have a breaking change. Credits to @mtd91429 who pointed out those inconsistencies in #1187
* owner_pwd ➔ owner_password * user_pwd ➔ user_password See #1187
* owner_pwd ➔ owner_password * user_pwd ➔ user_password See #1187
* indirect_reference ➔ indirect_ref and ido ➔ indirect_ref in PdfReader._get_object_from_stream and PdfWriter.get_object * dest➔ pagedest and dest_ref ➔ pagedest_ref in PdfWriter.add_outline_item_destination and PdfWriter.add_named_destination_object See #1187
Changed method parameter name for consistency as mentioned in #1187 - `position` ➔ `page_number` in `PdfMerger.merge` Improved the deprecation message of: - `dest` ➔ `page_destination` in `PdfWriter.add_outline_item_destination` and `PdfWriter.add_named_destination_object` - `user_pwd` ➔ `user_password` and `owner_pwd` ➔ `owner_password` in `PdfWriter.encrypt`
|
Explanation
As PyPDF2 has evolved, some of the internal naming conventions have not been consistent. One recently addressed issue was the outline/bookmark component; I think that was the largest example. As I have been exploring the code base, I have noticed others. I propose that these keywords be systematically implemented across the library and that the deprecation process utilizes an internally consistent process.
Below are the list of keywords that I can see which have inconsistent implementation (only including non-deprecated methods):
✔️
pagenum
,page_number
,pageNumber
(see #1365)PdfWriter.addBookmark
PdfWriter.add_outline_item
PdfWriter.add_named_destination
PdfWriter.add_uri
PdfWriter.add_link
pageNumber
is used in:PdfWriter.get_page
page_number
is used in:PdfWriter.add_annotation
PdfWriter.get_page
✔️
pagedest
anddest
(see #1467)pagedest
is used in:PdfWriter.add_link
dest
is used in:PdfWriter.add_outline_item_destination
PdfWriter.add_named_destination_object
✔️
indirect_ref
andido
(see #1467 and #1484)indirect_ref
is used in:PdfReader._get_page_number_by_indirect
PdfReader._flatten
indirect_reference
is used in:PdfReader._get_object_from_stream
ido
is used in:PdfWriter.get_object
✔️
pwd
andpassword
(see #1483)password
is used in:PdfReader.decrypt
pwd
is used in:PdfWriter.encrypt
(asuser_pwd
,owner_pwd
)Extrinsically inconsistent methods
There are some deprecated methods with keywords that have been changed in the updated function. For example,
PdfWriter.addAttachment
uses fname andPdfWriter.add_attachment
uses filename orPdfWriter.removeImages
usesignoreByteStringObject
andPdfWriter.remove_images
usesignore_byte_string_object
. These changes are silent.Intrinsically inconsistent methods
There are some methods which use keywords that are both snake_case and "smooshed" case. For example,
PdfReader._read_xref_tables_and_trailers
has bothstartxref
andxref_issue_nr
,Inconsistent deprecation implementation
Some of the keywords have been deprecated within the methods. For example,
PdfWriter.get_page
. Whereas other keywords have been deprecated via decorator; for example,PdfWriter.add_outline_item_dict
.Concluding remarks (for this long winded post)
I don't think all of these examples necessarily need to be changed; I've included them to be as thorough as possible. However, in my opinion, snake_case is best and explicit is better than implied via abbreviation (usually). Please list additional examples that you see and any proposed approaches.
The text was updated successfully, but these errors were encountered: