test: enable mypy typing checks for test/components/extractors/ - #12343
Open
abhati27 wants to merge 1 commit into
Open
test: enable mypy typing checks for test/components/extractors/#12343abhati27 wants to merge 1 commit into
abhati27 wants to merge 1 commit into
Conversation
Adds test/components/extractors/ to the mypy target in pyproject.toml and fixes the six type errors it surfaced. No changes to haystack source. - test_regex_text_extractor.py: annotate the empty message list, and ignore the arg-type on the call that deliberately passes a list[str] to assert the TypeError. - test_llm_metadata_extractor.py: ignore the call-arg on the constructor call that deliberately omits chat_generator to assert the TypeError, and narrow _chat_generator with isinstance before calling to_dict(), since the ChatGenerator protocol does not declare it. The narrowing also pins that from_dict rebuilt an OpenAIChatGenerator, which is what the test is for. - image/test_llm_document_content_extractor.py: the same call-arg ignore for the missing-chat_generator case, and bind Document.content to a local before len() so the str | None is narrowed. Each ignore sits directly under the pytest.raises that explains it, matching the approach in the joiners and embedders increments.
abhati27
requested review from
davidsbatista
and
a lite review from Copilot
and removed request for
a team
August 13, 2026 23:02
|
@abhati27 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
There was a problem hiding this comment.
Pull request overview
- Extends the
test:typesmypy target to includetest/components/extractors/and applies small typing-only adjustments in extractor tests so mypy passes without touchinghaystackruntime code.
Changes:
- Add
test/components/extractors/to thetypesscript target list inpyproject.toml. - Fix mypy errors in extractor tests via explicit annotations, narrowing, and scoped
# type: ignore[...]for deliberate negative tests. - Strengthen one test assertion by pinning
from_dict()to rebuild anOpenAIChatGeneratorinstance.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
pyproject.toml |
Adds test/components/extractors/ to the types (mypy) target paths. |
test/components/extractors/test_regex_text_extractor.py |
Annotates an empty messages list as list[ChatMessage] and scopes an ignore for an intentional type error test. |
test/components/extractors/test_llm_metadata_extractor.py |
Adds a scoped ignore for an intentional constructor misuse and narrows _chat_generator before calling implementation-specific APIs. |
test/components/extractors/image/test_llm_document_content_extractor.py |
Adds a scoped ignore for an intentional constructor misuse and narrows Document.content before len(). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
69
to
+71
| def test_init_fails_without_chat_generator(self): | ||
| with pytest.raises(TypeError): | ||
| LLMDocumentContentExtractor() | ||
| LLMDocumentContentExtractor() # type: ignore[call-arg] |
Comment on lines
99
to
+102
| with pytest.raises(TypeError): | ||
| _ = LLMMetadataExtractor(prompt="prompt {{document.content}}", expected_keys=["key1", "key2"]) | ||
| _ = LLMMetadataExtractor( # type: ignore[call-arg] | ||
| prompt="prompt {{document.content}}", expected_keys=["key1", "key2"] | ||
| ) |
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
(Deliberately not a closing keyword — #10396 tracks ~19 directories and only this one is covered here. It got auto-closed by #12272 and had to be reopened, so flagging it.)
Proposed Changes:
Adds
test/components/extractors/to thetypestarget inpyproject.tomland fixes the six type errors it surfaced. No changes tohaystacksource — test typing fixes plus the allowlist entry only.test_regex_text_extractor.py— annotate the empty message list aslist[ChatMessage], and ignore thearg-typeon the call that deliberately passes alist[str]to assert theTypeError.test_llm_metadata_extractor.py— ignore thecall-argon the constructor call that deliberately omitschat_generatorto assert theTypeError, and narrow_chat_generatorwithisinstancebefore callingto_dict(), since theChatGeneratorprotocol does not declare it.image/test_llm_document_content_extractor.py— the samecall-argignore for the missing-chat_generatorcase, and bindDocument.contentto a local beforelen()so thestr | Noneis narrowed.How did you test it?
hatch run test:typesis the full CI target, not just the new directory.Notes for the reviewer
One non-mechanical change worth a look: in
test_from_dict_openai, the assertion is onextractor._chat_generator.to_dict(), but the attribute is typed as theChatGeneratorprotocol, which doesn't declareto_dict. Rather than silence it, I narrowed withassert isinstance(extractor._chat_generator, OpenAIChatGenerator). That satisfies mypy and also pins thatfrom_dictrebuilt anOpenAIChatGenerator, which is what the test is named for — the protocol-vs-implementation gap this issue was opened to surface.The three
type: ignores are all deliberate negative tests, and each sits directly under thepytest.raises(TypeError)that explains it — consistent with how #12318 (joiners) and #11859 (embedders) handled the same situation.Checklist