test: type-check test/utils and add it to mypy config - #11728
Merged
Conversation
Enable mypy type checking for the test/utils directory (part of deepset-ai#10396) as a first piece-meal step toward typing the whole test suite. Fix the errors mypy surfaced across 11 files using real annotations where possible (annotating expected values, adding return types, narrowing float | None with asserts, annotating mock parameters). Where a test intentionally passes invalid input (inside pytest.raises) or monkeypatches a method, a scoped and commented type: ignore is used. No test behaviour is changed. Add test/utils/ to the test:types mypy paths in pyproject.toml.
|
@mustafakhokhar is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
…tils # Conflicts: # test/utils/test_jinja2_chat_extension.py
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
Contributor
Author
Contributor
|
Hey @mustafakhokhar thanks for opening the PR! I'll go ahead and give a review of this, this morning. |
sjrl
reviewed
Jul 1, 2026
sjrl
reviewed
Jul 1, 2026
sjrl
reviewed
Jul 1, 2026
sjrl
reviewed
Jul 1, 2026
Address review feedback on the test/utils type-checking work: - Fix the init_http_client overloads to carry defaults, so calling it with no/partial arguments matches an overload; remove the now-unnecessary call-overload ignores in the test. - test_auth: narrow with assert isinstance(secret, EnvVarSecret) instead of ignoring attr-defined on private-attribute access. - test_hf: pass a correctly-typed str tool_result instead of a dict, removing the arg-type ignores.
Contributor
Author
|
Thanks for the review @sjrl, all addressed 🙏
|
sjrl
reviewed
Jul 1, 2026
sjrl
reviewed
Jul 1, 2026
Revert the type(None) -> None change in test_type_serialization: those tests specifically verify NoneType as a typing-generic argument, so keep type(None) and use a scoped # type: ignore[misc] instead (intent-preserving fix).
Contributor
Author
|
Reverted 👍 — restored |
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/utils)Proposed Changes:
A first incremental step toward typing the whole test suite, as suggested in #10396 ("do it in a piece-meal approach where we only turn on type checking in a small part of tests and grow from there").
test/utils/to thetest:typesmypy paths inpyproject.toml.test/utilspassmypy, preferring real fixes over# type: ignore: proper type annotations,assert isinstance(...)narrowing, and correcting mis-typed test values.init_http_clientoverloads inhaystack/utils/http_client.pyto carry defaults (per review). The previous overloads omitted defaults, so calling it with no/partial arguments matched no overload. This is a typing-only change — the implementation and its runtime behaviour are unchanged — and it lets the corresponding test ignores be removed.# type: ignoreremains only where a test intentionally passes invalid input (e.g. a non-dicthttp_client_kwargs,error=None) or monkeypatches a method — each scoped to the exact error code.How did you test it?
hatch run test:types→ clean (now also type-checkstest/utils).hatch run test:unit test/utils/→ passes.hatch run fmtand pre-commit are clean.Notes for the reviewer
init_http_clientoverload signatures (typing only, no runtime behaviour change), so no release note is included (therenoCI check passes).attr-definedignores intest_authwithisinstancenarrowing, and gavetest_hf'stool_resultits correctstrtype.test_type_serialization(aUnionrepr change) — independent of this PR.Checklist
test:).renocheck passes).Implemented with the help of an AI assistant; I have reviewed all changes and run the relevant tests and quality checks.