Skip to content

STY: Type the destination and field trees as DictionaryObject - #3988

Merged
stefan6419846 merged 3 commits into
py-pdf:mainfrom
RavSinghChandan:fix-named-destinations-tree-type
Aug 24, 2026
Merged

STY: Type the destination and field trees as DictionaryObject#3988
stefan6419846 merged 3 commits into
py-pdf:mainfrom
RavSinghChandan:fix-named-destinations-tree-type

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

_get_named_destinations and _get_fields both walk trees that are plain dictionaries at runtime. A name tree node holds /Kids or /Names, and the AcroForm is a dictionary too — neither is a TreeObject, and neither function calls anything TreeObject adds on top of DictionaryObject. Both only do dictionary access.

The casts asserted TreeObject on objects that are DictionaryObject, so a typeguard run reports 16 failures across the reader, writer and form tests. _check_kids in the same file already takes Union[TreeObject, DictionaryObject], so I followed that.

Reverting the change brings the 16 failures back.

_get_named_destinations and _get_fields both walk name trees that are plain
dictionaries: a name tree node holds /Kids or /Names, and the AcroForm is a
dictionary too. Neither is a TreeObject, and neither function calls anything
TreeObject adds - both only do dictionary access.

The casts asserted TreeObject on objects that are DictionaryObject at runtime,
so a typeguard run reports 16 failures across the reader, writer and form
tests. Typed to match what is passed, following _check_kids in the same file,
which already accepts either.
PdfReader overrides _get_named_destinations, so narrowing it to TreeObject
while the base class accepts a DictionaryObject as well breaks substitution.
@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.98%. Comparing base (31b3298) to head (948f372).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3988      +/-   ##
==========================================
+ Coverage   97.95%   97.98%   +0.02%     
==========================================
  Files          57       57              
  Lines       11058    11098      +40     
  Branches     2072     2078       +6     
==========================================
+ Hits        10832    10874      +42     
+ Misses        126      125       -1     
+ Partials      100       99       -1     

☔ 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/_doc_common.py Outdated
TreeObject subclasses DictionaryObject, so naming both adds nothing.
@RavSinghChandan

Copy link
Copy Markdown
Contributor Author

No benefit, you're right — TreeObject subclasses DictionaryObject, so naming both adds nothing. Dropped it, and the signature is now Optional[DictionaryObject] in both _get_named_destinations and _get_fields, plus the PdfReader override so it still matches.

_check_kids further down the same file has the same redundant union, but I left it alone since it's outside what this PR touches. Happy to clean it up here or separately if you'd like.

@stefan6419846
stefan6419846 merged commit d716064 into py-pdf:main Aug 24, 2026
32 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