haystack icon indicating copy to clipboard operation
haystack copied to clipboard

Pyrefly strict mode rejects Haystack components

Open maxdswain opened this issue 1 month ago • 4 comments

Describe the bug
Pyrefly strict mode rejects Haystack components passed to Pipeline.add_component because their run signatures do not match Component.run(*args: Any, **kwargs: Any). This affects components generally, not just the example below.

Error message

Argument `DocumentWriter` is not assignable to parameter `instance` with type `Component` [bad-argument-type]

Expected behavior
Valid Haystack components type-check when added to a pipeline.

Additional context
Pyrefly passes with --strict-callable-subtyping=false; its strict preset enables that setting. The pipeline runs successfully.

To Reproduce

from haystack import Pipeline
from haystack.components.writers import DocumentWriter
from haystack.document_stores.in_memory import InMemoryDocumentStore

pipeline = Pipeline()
pipeline.add_component("writer", DocumentWriter(document_store=InMemoryDocumentStore()))

Run pyrefly check --preset strict repro.py with haystack-ai==3.4.1 and pyrefly==1.4.0.

FAQ Check

System:

  • OS: Arch Linux (kernel 7.2.9-arch1-1, x86_64)
  • Haystack version: 3.4.1
  • Python: 3.14.8; Pyrefly: 1.4.0

maxdswain avatar Oct 21 '26 19:10 maxdswain

Thanks for the report! Could you check whether keeping the strict preset but turning off just that one setting works for you? E.g.

[tool.pyrefly]
preset = "strict"
strict-callable-subtyping = false

That brings back the typing spec rule that treats (*args: Any, **kwargs: Any) as ..., which our Component protocol relies on. Pyright and mypy follow that rule by default.

sjrl avatar Oct 22 '26 06:10 sjrl

2. Thanks for the report! Could you check whether keeping the strict preset but turning off just that one setting works for you? E.g. [tool.pyrefly] preset = "strict" strict-callable-subtyping = false

That brings back the typing spec rule that treats `(*args: Any, **kwargs: Any)` as `...`, which our `Component` protocol relies on. Pyright and mypy follow that rule by default.

Yes, when turning off that setting the pyrefly check passes.

maxdswain avatar Oct 22 '26 18:10 maxdswain

@maxdswain for now we'd prefer not changing our protocol for Component if that's alright. Is disabling that one check fine enough for your use case?

sjrl avatar Nov 02 '26 07:11 sjrl

@sjrl I can continue to add inline comments disabling this pyrefly rule for code that uses haystack, it would be ideal if I didn't have to do that but doesn't impact functionality.

maxdswain avatar Nov 02 '26 21:11 maxdswain