Skip to content

BUG: Check the box names assigned to the area and clip preferences - #4014

Merged
stefan6419846 merged 3 commits into
py-pdf:mainfrom
RavSinghChandan:validate-box-name-preferences
Aug 26, 2026
Merged

stefan6419846 merged 3 commits into
py-pdf:mainfrom
RavSinghChandan:validate-box-name-preferences

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

/ViewArea, /ViewClip, /PrintArea and /PrintClip are each declared with an empty list of acceptable values:

cls.view_area = _add_prop_name("/ViewArea", [], None)

So any name is written through unchecked, and the generated docstrings read "Acceptable values: []":

>>> viewer_preferences.view_area = "/Nonsense"
>>> viewer_preferences.view_area
'/Nonsense'

All four name one of the five page boundaries, which PageAttributes already defines, so the allowed set is taken from there rather than spelled out again. direction and duplex beside them already reject a value outside their set.

Reverting the change fails the four new tests

@codecov

codecov Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.00%. Comparing base (38170a2) to head (5e51045).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4014   +/-   ##
=======================================
  Coverage   98.00%   98.00%           
=======================================
  Files          57       57           
  Lines       11124    11126    +2     
  Branches     2086     2086           
=======================================
+ Hits        10902    10904    +2     
  Misses        124      124           
  Partials       98       98           

☔ View full report in Codecov by Harness.
📢 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.

Comment thread pypdf/generic/_viewerpref.py Resolved
Comment thread pypdf/generic/_viewerpref.py Resolved
/ViewArea, /ViewClip, /PrintArea and /PrintClip were each declared with an
empty list of acceptable values, so any name was written through and the
generated docstrings read 'Acceptable values: []'.

All four name one of the five page boundaries, which PageAttributes already
defines, so they now reject anything else the way direction and duplex do.
@RavSinghChandan
RavSinghChandan force-pushed the validate-box-name-preferences branch from 25e7d23 to 8083adf Compare August 26, 2026 10:06
@RavSinghChandan

Copy link
Copy Markdown
Contributor Author

Both done. Dropped the alias, and the box names are now a BOX_NAMES constant next to f_obj, which the tests parametrise over so the five names are only written once.

@RavSinghChandan

Copy link
Copy Markdown
Contributor Author

Both done - dropped the alias, and the box names are now a BOX_NAMES constant next to f_obj, which the tests parametrise over so the five names are only written once.

Thanks for fixing the spacing, that was mine from resolving the conflict.

@stefan6419846
stefan6419846 merged commit b0ec95d into py-pdf:main Aug 26, 2026
27 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants