STY: Type the second argument of mult as the mapping it also accepts - #3989
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
|
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. |
effective_transformpasses the entries of aChainMapintomult, 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.multonly reads keys 0 through 5. The ChainMap holds those alongside theis_textandis_renderflags, 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.