-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAINT: Refactor Fit / Zoom parameters (#1437)
Introduce a new `PyPDF2.generic.Fit` class which captures the type and parameter for how a page should be fit in the viewer (e.g. when clicking on a PDF-internal link). The class has one method for each fit type which allows users to discover the different types via their IDE, e.g. `Fit.xyz(left=123, top=456, zoom=2)`. ## Breaking Change This **introduces a breaking change** that needs a major version bump. Affected are the following methods: * `PdfMerger.add_outline_item` used `fit: FitType` and `*args: ZoomArgType` parameters * `PdfWriter.add_outline_item` used `fit: FitType` and `*args: ZoomArgType` parameters * `AnnotationBuilder.link` used `fit: FitType = "/Fit"` and `fit_args: Tuple[ZoomArgType, ...] = tuple()` instead. Instead of having two arguments, we now have only one. To that argument, an object of the new `Fit` class must be passed. ## Why *args is problematic Using the `*args` pattern is problematic for two reasons: * **User-code readability**: * People cannot use the more expressive keyword-argument syntax in their code for the non-fit parameters * People may or may not use the keyword-parameter for the fit parameters * **Library extensions**: PyPDF2 cannot easily add new parameter to those functions; #1371 is the latest PR that stumbled over this issue * **Two parameter for one thing**: In general I don't like if we have two parameters for one topic
- Loading branch information
1 parent
ce0e190
commit 7633477
Showing
12 changed files
with
291 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.