Skip to content

Commit 6c73480

Browse files
julian-rischclaude
andauthored
chore: enable ANN ruff ruleset for type annotation enforcement (#10856)
* chore: enable ANN ruff ruleset, exclude components and testing dirs - Add ANN (flake8-annotations) to ruff select in pyproject.toml - Globally ignore ANN401 (Any) for legitimate dynamic types - Exclude haystack/components/** and haystack/testing/** from ANN checks (mirrors existing mypy disallow_incomplete_defs=false overrides) - Fix all 43 ANN violations in the remaining modules: - Add -> None to __post_init__ in breakpoints, file_content, image_content, sparse_embedding, streaming_chunk, tool, toolset, auth - Add -> str to __str__ in filter_policy, auth, hf (2x) - Add *args: Any, **kwargs: Any + return types to metaclass __call__ in component.py and document.py, and __new__ in chat_message.py - Add -> None to async _runner() in async_pipeline.py - Type _check_callable_compatibility args and return bool - Add Callable return type to _dispatch_bm25 - Type send_telemetry decorator params and return - Type __init_track__ and __setattr_warn__ wrapper functions - Type _parse_date, _parse_generic_args, async run() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore: fix ANN violations in .github/utils and docs-website scripts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore: fix mypy errors introduced by ANN annotations - async_pipeline.py: _runner() returns Mapping[str, Any], not None - dataclasses.py: extend type: ignore to cover arg-type in addition to call-arg Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * alphabetical order of ruff rules * fix: add ANN type annotations to haystack/components and remove per-file-ignore Fix all ANN (flake8-annotations) violations in haystack/components/ so the per-file-ignore for that directory can be removed entirely. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore: remove haystack.components.* from mypy disallow_incomplete_defs override All ANN type annotations have been added to haystack/components/, so the mypy override is no longer needed for that module. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5836b82 commit 6c73480

43 files changed

Lines changed: 72 additions & 64 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/utils/check_imports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def validate_module_imports(root_dir: str, exclude_subdirs: list[str] | None = N
4646
return imported, failed
4747

4848

49-
def main():
49+
def main() -> None:
5050
"""
5151
This script checks that all Haystack modules can be imported successfully.
5252

.github/utils/docstrings_checksum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pathlib import Path
55

66

7-
def docstrings_checksum(python_files: Iterator[Path]):
7+
def docstrings_checksum(python_files: Iterator[Path]) -> str:
88
"""
99
Calculate the checksum of the docstrings in the given Python files.
1010
"""

.github/utils/pyproject_to_requirements.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
parser.add_argument("--extra", default="")
1414

1515

16-
def resolve(target: str, extras: dict, results: set):
16+
def resolve(target: str, extras: dict, results: set) -> None:
1717
"""
1818
Resolve the dependencies for a given target.
1919
"""
@@ -30,7 +30,7 @@ def resolve(target: str, extras: dict, results: set):
3030
resolve(t, extras, results)
3131

3232

33-
def main(pyproject_path: Path, extra: str = ""):
33+
def main(pyproject_path: Path, extra: str = "") -> None:
3434
"""
3535
Convert a pyproject.toml file to a requirements.txt file.
3636
"""

docs-website/scripts/generate_requirements.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _package_name(dep: str) -> str:
3030
return candidate.strip()
3131

3232

33-
def fetch_haystack_deps(version="main"):
33+
def fetch_haystack_deps(version: str = "main") -> list[str]:
3434
"""
3535
Fetch and parse Haystack's pyproject.toml to extract dependencies.
3636
@@ -110,7 +110,7 @@ def fetch_haystack_deps(version="main"):
110110
return filtered_deps
111111

112112

113-
def main():
113+
def main() -> None:
114114
"""Entry point for generating requirements for docs snippet tests."""
115115
parser = argparse.ArgumentParser(
116116
description="Generate requirements.txt from Haystack's pyproject.toml for docs snippet testing"

haystack/components/agents/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ def _initialize_fresh_execution(
511511
generation_kwargs: dict[str, Any] | None = None,
512512
tools: ToolsType | list[str] | None = None,
513513
confirmation_strategy_context: dict[str, Any] | None = None,
514-
**kwargs,
514+
**kwargs: Any,
515515
) -> _ExecutionContext:
516516
"""
517517
Initialize execution context for a fresh run of the agent.

haystack/components/audio/whisper_local.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def run(
133133
documents = self.transcribe(sources, **whisper_params)
134134
return {"documents": documents}
135135

136-
def transcribe(self, sources: list[str | Path | ByteStream], **kwargs) -> list[Document]:
136+
def transcribe(self, sources: list[str | Path | ByteStream], **kwargs: Any) -> list[Document]:
137137
"""
138138
Transcribes the audio files into a list of Documents, one for each input file.
139139
@@ -166,7 +166,7 @@ def _get_path(self, source: str | Path | ByteStream) -> Path:
166166
source.to_file(path)
167167
return path
168168

169-
def _raw_transcribe(self, sources: list[str | Path | ByteStream], **kwargs) -> dict[Path, Any]:
169+
def _raw_transcribe(self, sources: list[str | Path | ByteStream], **kwargs: Any) -> dict[Path, Any]:
170170
"""
171171
Transcribes the given audio files. Returns the output of the model, a dictionary, for each input file.
172172

haystack/components/builders/chat_prompt_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def run(
213213
self,
214214
template: list[ChatMessage] | str | None = None,
215215
template_variables: dict[str, Any] | None = None,
216-
**kwargs,
216+
**kwargs: Any,
217217
) -> dict[str, list[ChatMessage]]:
218218
"""
219219
Renders the prompt template with the provided variables.

haystack/components/connectors/openapi_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# If you see that https://github.com/Dorthu/openapi3/pull/124/
2222
# is merged, we can remove this patch - notify authors of this code
2323
def patch_request(
24-
self,
24+
self: "Operation",
2525
base_url: str,
2626
*,
2727
data: Any | None = None,

haystack/components/embedders/backends/sentence_transformers_sparse_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def __init__(
103103
backend=backend,
104104
)
105105

106-
def embed(self, *, data: list[str], **kwargs) -> list[SparseEmbedding]:
106+
def embed(self, *, data: list[str], **kwargs: Any) -> list[SparseEmbedding]:
107107
embeddings_list = self.model.encode(
108108
data,
109109
convert_to_tensor=False, # output is a list of individual tensors

haystack/components/evaluators/context_relevance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def __init__(
157157
)
158158

159159
@component.output_types(score=float, results=list[dict[str, Any]])
160-
def run(self, **inputs) -> dict[str, Any]:
160+
def run(self, **inputs: Any) -> dict[str, Any]:
161161
"""
162162
Run the LLM evaluator.
163163

0 commit comments

Comments
 (0)