Pyrefly strict mode rejects Haystack components
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
- [x] Have you had a look at our new FAQ page?
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
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.
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 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 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.