Skip to content

test: enable mypy typing checks for test/components/converters - #12754

Merged
julian-risch merged 1 commit into
deepset-ai:mainfrom
ShousenZHANG:test/type-check-converters
Sep 15, 2026
Merged

julian-risch merged 1 commit into
deepset-ai:mainfrom
ShousenZHANG:test/type-check-converters

Conversation

@ShousenZHANG

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

Replaces the four per-entry converter paths on the types target with the directory itself, so test/components/converters/ is covered as a whole and that line gets four tokens shorter. Every other token on it is unchanged. Baseline was 55 errors across 9 modules.

Most of it is one cause. A list literal is invariant, so sources = ["a.json"] infers list[str], which is not a list[str | Path | ByteStream]; annotating the variable settles it. Annotating the test_files_path fixture then turned eight more list[Any] lists into list[Path], which needed the same treatment — 32 annotations in total, across eight modules, all of the same shape.

The rest:

  • test_files_path: Path on nine tests, matching test_textfile_to_document.py in the same directory, plus caplog: pytest.LogCaptureFixture and one Literal["markdown", "plain"].
  • Narrowed, not suppressed: assert content is not None before in content; isinstance(document, Document) and isinstance(attachment, ByteStream) in the MSG test, where the lists hold a union; and isinstance(deserialized_adapter, OutputAdapter) after get_component, which is typed as returning the protocol — following test/core/pipeline/test_pipeline_base.py. That last one also makes the assertion check that deserialization returns the concrete component.
  • os.path.basename reads a str local instead of a union element, rather than casting at the call.

Seven suppressions, in two groups. Three are __haystack_output__ / __haystack_input__, injected by @component where mypy cannot see them; test/core/component/test_component.py already suppresses those the same way. Four are tests whose subject is the type error: sources=[123], char_margin=None in test_arg_is_none, and link_format="invalid" twice, each asserting the component rejects the value.

How did you test it?

  • Before: mypy on test/components/converters/ -> 55 errors. After: zero, 22 source files checked.
  • pytest test/components/converters/ -> 289 passed.
  • Full unit suite -> 6399 passed. ruff check / ruff format --check over the repo -> clean, 6804 files. check_imports.py -> 262 modules.
  • Four things still fail on my machine and all four reproduce identically on a clean main checkout, so none is from this change: two unit tests and one mypy error from a newer local openai than the tests expect plus the Windows mime registry, and the two test_multi_file_converter.py integration tests, which are downstream of that same mime mismatch.

With this, test/components/converters/ is fully covered. test/components/agents/ (106 errors) and the five modules at test/ root (18) are what remain outside the target.

No release note: test-only, which AGENTS.md excludes from the release-note requirement.


This PR was written with AI assistance.

Replaces the four per-entry converter paths on the `types` script with the
directory itself and fixes the 55 errors that surfaces. Every other token on that
line is unchanged.

Most of it is one cause. A list literal is invariant, so `sources = ["a.json"]`
infers `list[str]`, which is not a `list[str | Path | ByteStream]`; annotating the
variable settles it. That accounts for 32 of the annotations, across eight
modules. Annotating the `test_files_path` fixture then turned eight more
`list[Any]` lists into `list[Path]`, which needed the same treatment.

The rest:

- `test_files_path: Path` on nine tests, matching `test_textfile_to_document.py`,
  plus `caplog: pytest.LogCaptureFixture` and one `Literal["markdown", "plain"]`.
- Narrowed rather than suppressed: `assert content is not None` before `in
  content`, `isinstance(document, Document)` / `isinstance(attachment, ByteStream)`
  in the MSG test, and `isinstance(deserialized_adapter, OutputAdapter)` after
  `get_component`, which is typed as returning the protocol. The last one follows
  `test/core/pipeline/test_pipeline_base.py`.
- `os.path.basename` now reads a `str` local instead of the union element.

Seven suppressions, in two groups. Three are `__haystack_output__` /
`__haystack_input__`, injected by `@component` where mypy cannot see them, and
`test/core/component/test_component.py` already suppresses those the same way.
Four are tests whose subject is the type error: `sources=[123]`,
`char_margin=None` in `test_arg_is_none`, and `link_format="invalid"` twice, each
asserting the component rejects it.

Part of #10396.
@ShousenZHANG
ShousenZHANG requested a review from a team as a code owner September 15, 2026 02:41
@ShousenZHANG
ShousenZHANG requested review from julian-risch and a lite review from Copilot and removed request for a team and Copilot September 15, 2026 02:41
@vercel

vercel Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

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

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

This PR does not seem to contain any modification to coverable code.

@julian-risch julian-risch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for another PR @ShousenZHANG !

@julian-risch
julian-risch merged commit 9c7e2a9 into deepset-ai:main Sep 15, 2026
24 of 25 checks passed
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