Skip to content

STY: Type the second argument of mult as the mapping it also accepts - #3989

Merged
stefan6419846 merged 2 commits into
py-pdf:mainfrom
RavSinghChandan:fix-mult-matrix-type
Aug 24, 2026
Merged

STY: Type the second argument of mult as the mapping it also accepts#3989
stefan6419846 merged 2 commits into
py-pdf:mainfrom
RavSinghChandan:fix-mult-matrix-type

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

effective_transform passes the entries of a ChainMap into mult, which was annotated to take two lists. The call carried a # type: ignore[arg-type] with a comment noting that the dict has integer keys 0-5.

mult only reads keys 0 through 5. The ChainMap holds those alongside the is_text and is_render flags, so it satisfies the function as it stands. Annotating that removes eight typeguard failures in the text extraction and page tests, and the suppression along with them.

Reverting brings the eight back.

effective_transform passes the entries of a ChainMap into mult, which was
annotated to take two lists. The call carried a type: ignore[arg-type] and a
comment noting that the dict has integer keys 0-5.

mult only reads keys 0 through 5, and the ChainMap holds those alongside the
is_text and is_render flags, so the mapping satisfies the function as it
stands. Annotating that removes eight typeguard failures in the text
extraction and page tests, and the suppression with them.
@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 (ec6484c).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3989      +/-   ##
==========================================
+ Coverage   97.95%   97.98%   +0.02%     
==========================================
  Files          57       57              
  Lines       11058    11100      +42     
  Branches     2072     2078       +6     
==========================================
+ Hits        10832    10876      +44     
+ 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/_text_extraction/__init__.py Outdated
The only string keys the ChainMap ever holds are is_text and is_render, so
spelling them out is more accurate than str. Applied to the type alias as
well, otherwise the call site still widens to str.
@RavSinghChandan

Copy link
Copy Markdown
Contributor Author

The strings and booleans never reach the calculation — mult only reads keys 0 through 5, which are the matrix floats. The other two entries are is_text and is_render, which the ChainMap carries alongside the matrix; I instrumented a run over the test corpus to confirm those are the only string keys that ever appear.

So yes, a Literal is the better fit. Applied. It also had to go on TextStateManagerChainMapType itself, otherwise the key type widens back to str at the call site and mypy rejects it.

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