test: enable mypy typing checks for test/components/samplers/ - #12433
Open
sainikhiljuluri wants to merge 1 commit into
Open
test: enable mypy typing checks for test/components/samplers/#12433sainikhiljuluri wants to merge 1 commit into
sainikhiljuluri wants to merge 1 commit into
Conversation
Adds test/components/samplers/ to the mypy allowlist, continuing the effort to type-check our test files. Both errors were `sorted()` over `[doc.score for doc in docs]`, which mypy rejects because `Document.score` is `float | None` and so is not orderable. Narrowed with `if doc.score is not None`, the idiom already used in the retriever and joiner tests. The first site also asserts the narrowed list keeps every document. Without that, the filter would have quietly weakened the test: the unfiltered `sorted()` used to catch a missing score via TypeError, and three documents filtered to two would still match the `[:2]` slice the assertion compares against. The second site needs no such guard because the pre-existing `len(docs_filtered) == len(docs)` assertion above it already ties both sides to the input length. Behaviour is unchanged - all 14 tests pass with and without this change. Relates to deepset-ai#10396
sainikhiljuluri
requested review from
davidsbatista
and removed request for
a team
August 22, 2026 07:01
|
@sainikhiljuluri is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
38 tasks
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
Relates to #10396
Proposed Changes
Adds
test/components/samplers/to thetypesmypy allowlist, continuing the effort in #10396 to type-check our test files. The directory contains only__init__.pyandtest_top_p.py, so this covers it completely.Both baseline errors were the same one:
Document.scoreisfloat | None, which isn't orderable, sosorted([doc.score for doc in docs])is rejected. I narrowed withif doc.score is not None— the idiom already used for this exact expression intest_multi_query_text_retriever.py:149,191,test_multi_query_embedding_retriever.py:279andtest_multi_query_text_retriever_async.py:70,178.Why one site gets an extra assertion and the other doesn't
The filter on its own would have quietly weakened
test_run. The unfilteredsorted()was incidentally enforcing "every document has a score" by raisingTypeError, and filtering throws that away. Concretely, if a document lost its score, three scores would filter to two, andsorted_scores[:2]would still match the two filtered documents — every assertion in the test would pass. Sotest_runalso asserts the narrowed list kept every document, which restores exactly the invariant theTypeErrorused to provide.test_run_top_p_1needs no such guard: the pre-existingassert len(docs_filtered) == len(docs)above it already ties both sides to the input length, so a dropped score makes the lists different lengths and fails the comparison.I also considered
# type: ignore[type-var]. It's shorter, butAGENTS.mdasks to avoidtype: ignorewhere possible andwarn_unused_ignores = truemakes ignores a maintenance liability.assert all(s is not None for s in scores)doesn't work — it doesn't narrow the comprehension's element type, and mypy still errors.How did you test it?
typesscope (449 source files) to confirm nothing else regressed.ruff format --checkandruff checkare clean.No release note: this is a tests-only change, matching the precedent in #12327, #12394 and #12333.
Checklist
Note
This contribution was AI-assisted (Claude Code). The analysis, the mutation testing behind the assertion argument above, and the verification commands were run and reviewed before submitting.