Repository navigation
test: enable mypy typing checks for test/hooks/compaction - #12749
Merged
julian-risch merged 2 commits intoSep 14, 2026
Merged
Conversation
ShousenZHANG
requested review from
julian-risch
and removed request for
a team
September 14, 2026 10:19
Contributor
|
@ShousenZHANG is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
Adds `test/hooks/compaction/` to the `types` script and fixes the 29 errors it surfaces. The bulk of them, 15 of 29, are one root cause: `_RecordingCompactor` did not implement `to_dict`, which `Compactor` declares, so every instantiation of the stub was an abstract-class error. It now serializes through `default_to_dict`, the same way `KeepIterating` does in `test/hooks/budget`. The rest: - annotate `_hook` and `_agent`, and type the two `settings` dicts that are splatted into `CompactionHook`, whose keyword arguments are not all `object`; - narrow `compacted` before `len()`, and bind `tool_call_result` to a local before reading `.origin` / `.result` off it, rather than suppressing the optional-access errors; - assert `isinstance(restored, SlidingWindowCompactor)` after `from_dict`, which is typed as returning the protocol and so does not expose `min_keep_steps` or `omission_note`. Part of #10396.
ShousenZHANG
force-pushed
the
test/type-check-hooks-compaction
branch
from
September 14, 2026 13:46
185f93e to
40a5878
Compare
julian-risch
approved these changes
Sep 14, 2026
julian-risch
left a comment
Member
There was a problem hiding this comment.
LGTM! Thank you for another PR @ShousenZHANG !
Resolve pyproject.toml conflict: keep both test/hooks/compaction/ and test/components/converters/image/ in the mypy types target. Co-Authored-By: Claude Fable 5.1 <[email protected]>
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.
Related Issues
test/hooks/root modules) and test: enable mypy typing checks for test/hooks/budget #12710 (test/hooks/budget/)Proposed Changes:
Adds
test/hooks/compaction/to thetypestarget. Baseline was 29 errors; over half had one cause.abstract— every instantiation of_RecordingCompactorintest_hooks.pyfailed because the stub never implementedto_dict, which theCompactorprotocol declares. Implemented withdefault_to_dict, matchingKeepIteratingintest/hooks/budget/test_hooks.pyfrom test: enable mypy typing checks for test/hooks/budget #12710. Fixed structurally, no suppression.arg-type— the twosettingsdicts splatted intoCompactionHookwere inferred asdict[str, object], but its keyword arguments areint,floatandTokenCounter | None. They now carry an explicitdict[str, Any]annotation.no-untyped-def—_hookand_agentare annotated._agenttakesdict[HookPoint, list[Hook]] | None, matchingAgent.__init__, because one test calls_agent(None).union-attr/arg-typeon optional access —compactedis narrowed withassert compacted is not Nonebeforelen(), andtool_call_resultis bound to a local before.origin/.resultis read off it.assert x is not Noneon a subscript expression does not narrow, which is why the loop intest_tool_result_pruning.pyneeded the local.attr-defined—SlidingWindowCompactor.from_dictis typed as returning the protocol, somin_keep_stepsandomission_noteare not visible on it. Narrowed withisinstancerather than suppressed, which also makes the assertion check thatfrom_dictreturns the concrete compactor.Zero suppressions added. The optional-access and protocol-return cases are the ones where a
# type: ignorewould have been quickest and would also have stopped the assertions from proving anything.How did you test it?
mypyontest/hooks/compaction/-> 29 errors.hatch run test:typesis clean for everything this PR touches.pytest test/hooks/-> 325 passed, 1 skipped.pytest test/hooks/compaction/-> 136 passed.test_byte_stream.pymime guessing,test_openai_responses_conversion.py) reproduce identically on a cleanmaincheckout — Windows mime registry and a newer localopenaithan the tests expect, neither related to this change.hatch run fmt-check-> clean, 6804 files.check_imports.py-> 262 modules imported.tool_result_offloading/is left alone — #12720 is already on it. After that lands,test/hooks/is fully covered.No release note: test-only, which AGENTS.md excludes from the release-note requirement.
This PR was written with AI assistance.