Repository navigation
STY: Type read_object as the PdfObject it always returns - #4038
Merged
stefan6419846 merged 1 commit intoSep 1, 2026
Merged
Conversation
RavSinghChandan
force-pushed
the
read-object-return-type
branch
from
September 1, 2026 11:28
7e1fdab to
a04176b
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
stefan6419846
approved these changes
Sep 1, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.