Skip to content

STY: Type read_object as the PdfObject it always returns - #4038

Merged
stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:read-object-return-type
Sep 1, 2026
Merged

stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:read-object-return-type

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

read_object is annotated Union[PdfObject, int, str, ContentStream], but it never
returns an int or a str. Every branch hands back a PdfObject subclass - NameObject,
DictionaryObject, ArrayObject, BooleanObject, NullObject, NumberObject or
IndirectObject - and ContentStream is a DecodedStreamObject, so it is already a
PdfObject too.

Because the annotation was wider than the truth, the callers had to work around it.
_get_object_from_stream repeated the same union, and get_object carried two
type: ignore[assignment] comments plus two cast(PdfObject, retval) calls that existed
only to undo the phantom types again before decrypt_object. Narrowing the return type
lets all six go, including the last bare type: ignore left in the package.

Nothing changes at runtime, so I have not added tests. mypy reports the same 11
pre-existing errors before and after, all in _crypt_providers/_pycryptodome.py.

One thing worth flagging: I could not run the tests that download the corpus locally,
so those are down to CI. The offline suite passes, 1231 tests.

@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.04%. Comparing base (17d57a5) to head (a04176b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4038   +/-   ##
=======================================
  Coverage   98.03%   98.04%           
=======================================
  Files          57       57           
  Lines       11210    11208    -2     
  Branches     2110     2110           
=======================================
- Hits        10990    10989    -1     
+ Misses        123      122    -1     
  Partials       97       97           

☔ 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.

@stefan6419846
stefan6419846 merged commit 939ae0c into py-pdf:main Sep 1, 2026
31 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