Skip to content

ROB: Raise a clear TypeError for an unsupported page_number in add_outline_item - #4080

Merged
stefan6419846 merged 2 commits into
py-pdf:mainfrom
RavSinghChandan:outline-item-page-number-type
Sep 16, 2026
Merged

stefan6419846 merged 2 commits into
py-pdf:mainfrom
RavSinghChandan:outline-item-page-number-type

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

add_outline_item's page_number branch only assigns page_ref for
IndirectObject, PageObject and int. Anything else falls through with no
assignment, so the very next line — if page_ref is None: — raises
UnboundLocalError instead of telling the caller what was actually wrong.

writer.add_outline_item("Title", "not-a-valid-type")
-> UnboundLocalError: cannot access local variable 'page_ref'

Added an explicit else branch that raises TypeError naming the bad type,
matching the convention already used elsewhere in this file (e.g.
add_annotation's "page: invalid type").

Offline suite passes, 1340 tests.

Used Claude (Opus) to help locate and patch this; I reviewed and tested the change.

@codecov

codecov Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.14%. Comparing base (3a1111d) to head (a05bacb).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4080      +/-   ##
==========================================
+ Coverage   98.12%   98.14%   +0.02%     
==========================================
  Files          59       59              
  Lines       11490    11514      +24     
  Branches     2150     2149       -1     
==========================================
+ Hits        11274    11300      +26     
  Misses        122      122              
+ Partials       94       92       -2     

☔ 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 tests/test_writer.py Resolved
@stefan6419846 stefan6419846 changed the title BUG: Raise a clear TypeError for an unsupported page_number in add_outline_item ROB: Raise a clear TypeError for an unsupported page_number in add_outline_item Sep 16, 2026
@stefan6419846
stefan6419846 merged commit 6393e9f into py-pdf:main Sep 16, 2026
39 of 49 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