Skip to content

test: type-check test/utils and add it to mypy config#11728

Open
mustafakhokhar wants to merge 3 commits into
deepset-ai:mainfrom
mustafakhokhar:test/typecheck-test-utils
Open

test: type-check test/utils and add it to mypy config#11728
mustafakhokhar wants to merge 3 commits into
deepset-ai:mainfrom
mustafakhokhar:test/typecheck-test-utils

Conversation

@mustafakhokhar

Copy link
Copy Markdown

Related Issues

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").

  • Add test/utils/ to the test:types mypy paths in pyproject.toml.
  • Make test/utils pass mypy by fixing the errors it surfaced across 11 files, preferring real type annotations (annotating expected values, adding -> None / parameter types, narrowing float | None with assert ... is not None, annotating mock parameters).
  • Where a test intentionally passes invalid input (inside pytest.raises) or monkeypatches a method, a scoped, commented # type: ignore[<code>] is used (no bare ignores).
  • No test behaviour, assertions, or values are changed — only type annotations, narrowing asserts, and scoped ignores.

How did you test it?

  • hatch run test:types → clean (now also type-checks test/utils).
  • hatch run test:unit test/utils/ → passes (see reviewer note about one unrelated pre-existing failure).
  • hatch run fmt and the pre-commit hooks are clean.

Notes for the reviewer

  • Tests/CI-only change (no haystack/ source changes), so no release note is included.
  • test/utils/test_type_serialization.py::test_output_type_serialization_typing_generic_with_nonetype fails only on Python 3.14 (Union[str, int, None] now reprs as str | int | None). This is unrelated to this PR, reproduces on main, and that assertion is untouched here.
  • All # type: ignore comments are scoped to specific error codes with a short justification — happy to adjust any.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • Type annotations only; no behaviour change (no new unit tests needed).
  • I've used a conventional commit type for my PR title (test:).
  • I have documented my code.
  • Release note — N/A: tests/CI-only change (maintainers may add ignore-for-release-notes).
  • I have run pre-commit hooks and fixed any issue.

Implemented with the help of an AI assistant; I have reviewed all changes and run the relevant tests and quality checks.

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 mustafakhokhar requested a review from a team as a code owner June 23, 2026 08:16
@mustafakhokhar mustafakhokhar requested review from sjrl and removed request for a team June 23, 2026 08:16
@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

@mustafakhokhar is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants