Skip to content

Commit 7d7a7e7

Browse files
julian-rischclaude
andauthored
chore: enable ANN ruff ruleset for elasticsearch integration (#2986)
Add ANN (flake8-annotations) to ruff select, ignore ANN401 (Any is used legitimately for **kwargs and ES SDK boundaries), exclude tests from ANN checks, and add missing -> None return type annotations to __init__ and _ensure_initialized. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent bda5636 commit 7d7a7e7

5 files changed

Lines changed: 10 additions & 7 deletions

File tree

integrations/elasticsearch/pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ line-length = 120
8585
[tool.ruff.lint]
8686
select = [
8787
"A",
88+
"ANN",
8889
"ARG",
8990
"B",
9091
"C",
@@ -125,6 +126,8 @@ ignore = [
125126
"PLR0912",
126127
"PLR0913",
127128
"PLR0915",
129+
# Allow `Any` - used legitimately for dynamic types and SDK boundaries
130+
"ANN401",
128131
]
129132

130133
[tool.ruff.lint.isort]
@@ -134,8 +137,8 @@ known-first-party = ["haystack_integrations"]
134137
ban-relative-imports = "parents"
135138

136139
[tool.ruff.lint.per-file-ignores]
137-
# Tests can use magic values, assertions, and relative imports
138-
"tests/**/*" = ["PLR2004", "S101", "TID252"]
140+
# Tests can use magic values, assertions, relative imports, and don't need type annotations
141+
"tests/**/*" = ["PLR2004", "S101", "TID252", "ANN"]
139142

140143
[tool.coverage.run]
141144
source = ["haystack_integrations"]

integrations/elasticsearch/src/haystack_integrations/components/retrievers/elasticsearch/bm25_retriever.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(
5252
top_k: int = 10,
5353
scale_score: bool = False,
5454
filter_policy: str | FilterPolicy = FilterPolicy.REPLACE,
55-
):
55+
) -> None:
5656
"""
5757
Initialize ElasticsearchBM25Retriever with an instance ElasticsearchDocumentStore.
5858

integrations/elasticsearch/src/haystack_integrations/components/retrievers/elasticsearch/embedding_retriever.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(
5353
top_k: int = 10,
5454
num_candidates: int | None = None,
5555
filter_policy: str | FilterPolicy = FilterPolicy.REPLACE,
56-
):
56+
) -> None:
5757
"""
5858
Create the ElasticsearchEmbeddingRetriever component.
5959

integrations/elasticsearch/src/haystack_integrations/components/retrievers/elasticsearch/sql_retriever.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(
4242
document_store: ElasticsearchDocumentStore,
4343
raise_on_failure: bool = True,
4444
fetch_size: int | None = None,
45-
):
45+
) -> None:
4646
"""
4747
Creates the ElasticsearchSQLRetriever component.
4848

integrations/elasticsearch/src/haystack_integrations/document_stores/elasticsearch/document_store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def __init__(
8686
api_key_id: Secret | str | None = Secret.from_env_var("ELASTIC_API_KEY_ID", strict=False),
8787
embedding_similarity_function: Literal["cosine", "dot_product", "l2_norm", "max_inner_product"] = "cosine",
8888
**kwargs: Any,
89-
):
89+
) -> None:
9090
"""
9191
Creates a new ElasticsearchDocumentStore instance.
9292
@@ -156,7 +156,7 @@ def __init__(
156156
],
157157
}
158158

159-
def _ensure_initialized(self):
159+
def _ensure_initialized(self) -> None:
160160
"""
161161
Ensures both sync and async clients are initialized and the index exists.
162162
"""

0 commit comments

Comments
 (0)