Skip to content

Commit 8aecd85

Browse files
committed
Fix linter warnings and errors
1 parent a8bac2c commit 8aecd85

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

integrations/dspy/pyproject.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ classifiers = [
2222
"Programming Language :: Python :: Implementation :: CPython",
2323
"Programming Language :: Python :: Implementation :: PyPy",
2424
]
25-
dependencies = ["haystack-ai>=2.0.0", "dspy>=3.0.0"]
25+
dependencies = ["haystack-ai>=2.22.0", "dspy>=3.0.0"]
2626

2727
[project.urls]
2828
Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/dspy#readme"
@@ -73,6 +73,10 @@ non_interactive = true
7373
check_untyped_defs = true
7474
disallow_incomplete_defs = true
7575

76+
[[tool.mypy.overrides]]
77+
module = "dspy.*"
78+
ignore_missing_imports = true
79+
7680
[tool.hatch.metadata]
7781
allow-direct-references = true
7882

@@ -129,7 +133,7 @@ ban-relative-imports = "parents"
129133

130134
[tool.ruff.lint.per-file-ignores]
131135
# Tests can use magic values, assertions, and relative imports
132-
"tests/**/*" = ["PLR2004", "S101", "TID252"]
136+
"tests/**/*" = ["PLR2004", "S101", "TID252", "ARG002"]
133137
# Examples can print their output
134138
"examples/**" = ["T201"]
135139

integrations/dspy/src/haystack_integrations/components/generators/dspy/chat/chat_generator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def _configure_dspy_lm(model: str, api_base: str | None = None, **kwargs: Any) -
2525
return lm
2626

2727

28-
def _get_dspy_module_class(module_type: str):
28+
def _get_dspy_module_class(module_type: str) -> type:
2929
"""
3030
Map a module type string to the corresponding DSPy module class.
3131
@@ -148,7 +148,7 @@ def __init__(
148148
module_class = _get_dspy_module_class(self.module_type)
149149
self._module = module_class(self.signature, **self.module_kwargs)
150150

151-
def _build_dspy_inputs(self, prompt: str, **kwargs) -> dict[str, Any]:
151+
def _build_dspy_inputs(self, prompt: str, **kwargs: Any) -> dict[str, Any]:
152152
"""Build the input dict for the DSPy module call."""
153153
if self.input_mapping:
154154
dspy_inputs = {}
@@ -180,8 +180,8 @@ def _extract_last_user_message(messages: list[ChatMessage]) -> str:
180180
"""Extract the text of the last user message from a list of chat messages."""
181181
for msg in reversed(messages):
182182
if msg.role == ChatRole.USER:
183-
return msg.text
184-
return messages[-1].text
183+
return msg.text or ""
184+
return messages[-1].text or ""
185185

186186
def _signature_to_string(self) -> str:
187187
"""
@@ -227,7 +227,7 @@ def run(
227227
self,
228228
messages: list[ChatMessage],
229229
generation_kwargs: dict[str, Any] | None = None,
230-
**kwargs,
230+
**kwargs: Any,
231231
) -> dict[str, Any]:
232232
"""
233233
Run the DSPy module on the given messages.
@@ -256,7 +256,7 @@ async def run_async(
256256
self,
257257
messages: list[ChatMessage],
258258
generation_kwargs: dict[str, Any] | None = None,
259-
**kwargs,
259+
**kwargs: Any,
260260
) -> dict[str, Any]:
261261
"""
262262
Asynchronously run the DSPy module on the given messages.

integrations/dspy/tests/test_chat_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def test_run_with_input_mapping(self, mock_dspy_module):
405405
input_mapping={"context": "context", "question": "question"},
406406
)
407407
messages = [ChatMessage.from_user("What is ML?")]
408-
response = component.run(messages=messages, context="Machine learning is a subset of AI.")
408+
component.run(messages=messages, context="Machine learning is a subset of AI.")
409409

410410
call_kwargs = mock_dspy_module.call_args.kwargs
411411
assert call_kwargs.get("context") == "Machine learning is a subset of AI."

0 commit comments

Comments
 (0)