Skip to content

Commit 750562b

Browse files
authored
fix: fix Jina types + add py.typed (#2020)
1 parent 77e53cc commit 750562b

File tree

7 files changed

+14
-25
lines changed

7 files changed

+14
-25
lines changed

.github/workflows/jina.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,9 @@ jobs:
4949
- name: Install Hatch
5050
run: pip install --upgrade hatch
5151

52-
# TODO: Once this integration is properly typed, use hatch run test:types
53-
# https://github.com/deepset-ai/haystack-core-integrations/issues/1771
5452
- name: Lint
5553
if: matrix.python-version == '3.9' && runner.os == 'Linux'
56-
run: hatch run fmt-check && hatch run lint:typing
54+
run: hatch run fmt-check && hatch run test:types
5755

5856
- name: Generate docs
5957
if: matrix.python-version == '3.9' && runner.os == 'Linux'

integrations/jina/pyproject.toml

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,14 @@ integration = 'pytest -m "integration" {args:tests}'
6868
all = 'pytest {args:tests}'
6969
cov-retry = 'all --cov=haystack_integrations --reruns 3 --reruns-delay 30 -x'
7070

71-
types = "mypy --install-types --non-interactive --explicit-package-bases {args:src/ tests}"
72-
73-
# TODO: remove lint environment once this integration is properly typed
74-
# test environment should be used instead
75-
# https://github.com/deepset-ai/haystack-core-integrations/issues/1771
76-
[tool.hatch.envs.lint]
77-
installer = "uv"
78-
detached = true
79-
dependencies = ["pip", "mypy>=1.0.0", "ruff>=0.0.243"]
80-
81-
[tool.hatch.envs.lint.scripts]
82-
typing = "mypy --install-types --non-interactive --explicit-package-bases {args:src/ tests}"
71+
types = """mypy -p haystack_integrations.components.connectors.jina \
72+
-p haystack_integrations.components.embedders.jina {args}"""
8373

74+
[tool.mypy]
75+
install_types = true
76+
non_interactive = true
77+
check_untyped_defs = true
78+
disallow_incomplete_defs = true
8479

8580
[tool.ruff]
8681
target-version = "py38"
@@ -156,8 +151,4 @@ exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]
156151

157152
[tool.pytest.ini_options]
158153
minversion = "6.0"
159-
markers = ["unit: unit tests", "integration: integration tests"]
160-
161-
[[tool.mypy.overrides]]
162-
module = ["haystack.*", "haystack_integrations.*", "pytest.*"]
163-
ignore_missing_imports = true
154+
markers = ["integration: integration tests"]

integrations/jina/src/haystack_integrations/components/connectors/jina/reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def _json_to_document(self, data: dict) -> Document:
104104
return document
105105

106106
@component.output_types(documents=List[Document])
107-
def run(self, query: str, headers: Optional[Dict[str, str]] = None):
107+
def run(self, query: str, headers: Optional[Dict[str, str]] = None) -> Dict[str, List[Document]]:
108108
"""
109109
Process the query/URL using the Jina AI reader service.
110110
@@ -131,7 +131,7 @@ def run(self, query: str, headers: Optional[Dict[str, str]] = None):
131131
# raw response: we just return a single Document with text
132132
if not self.json_response:
133133
meta = {"content_type": response.headers["Content-Type"], "query": query}
134-
return {"documents": [Document(content=response.content, meta=meta)]}
134+
return {"documents": [Document(content=response.text, meta=meta)]}
135135

136136
response_json = json.loads(response.content).get("data", {})
137137
if self.mode == JinaReaderMode.SEARCH:

integrations/jina/src/haystack_integrations/components/connectors/py.typed

Whitespace-only changes.

integrations/jina/src/haystack_integrations/components/embedders/jina/document_embedder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def _embed_batch(
190190
return all_embeddings, metadata
191191

192192
@component.output_types(documents=List[Document], meta=Dict[str, Any])
193-
def run(self, documents: List[Document]):
193+
def run(self, documents: List[Document]) -> Dict[str, Any]:
194194
"""
195195
Compute the embeddings for a list of Documents.
196196

integrations/jina/src/haystack_integrations/components/embedders/jina/text_embedder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def to_dict(self) -> Dict[str, Any]:
9494
:returns:
9595
Dictionary with serialized data.
9696
"""
97-
kwargs = {
97+
kwargs: Dict[str, Any] = {
9898
"api_key": self.api_key.to_dict(),
9999
"model": self.model_name,
100100
"prefix": self.prefix,
@@ -122,7 +122,7 @@ def from_dict(cls, data: Dict[str, Any]) -> "JinaTextEmbedder":
122122
return default_from_dict(cls, data)
123123

124124
@component.output_types(embedding=List[float], meta=Dict[str, Any])
125-
def run(self, text: str):
125+
def run(self, text: str) -> Dict[str, Any]:
126126
"""
127127
Embed a string.
128128

integrations/jina/src/haystack_integrations/components/embedders/py.typed

Whitespace-only changes.

0 commit comments

Comments
 (0)