Skip to content

Commit bbd57d7

Browse files
style: fix linting and mypy type errors in llm_tools
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6a9b162 commit bbd57d7

3 files changed

Lines changed: 34 additions & 26 deletions

File tree

codeflash/verification/__init__.py

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

66

7-
def __getattr__(name: str): # noqa: ANN202
7+
def __getattr__(name: str) -> object:
88
"""Lazy import for LLM tools to avoid circular imports."""
99
if name in (
1010
"AVAILABLE_TOOLS",

codeflash/verification/llm_tools.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88

99
import os
1010
from pathlib import Path
11-
from typing import Any
11+
from typing import TYPE_CHECKING, Any, TypedDict
12+
13+
if TYPE_CHECKING:
14+
from collections.abc import Callable
1215

1316
from pydantic import BaseModel, Field
1417

15-
from codeflash.models.models import TestFile, TestFiles, TestType
18+
from codeflash.models.models import TestFile, TestFiles
19+
from codeflash.models.test_type import TestType
1620
from codeflash.verification.parse_test_output import parse_test_xml
1721
from codeflash.verification.test_runner import run_behavioral_tests
1822
from codeflash.verification.verification_utils import TestConfig
@@ -137,7 +141,7 @@ def run_behavioral_tests_tool(
137141
project_root: str,
138142
test_framework: str = "pytest",
139143
pytest_timeout: int | None = 30,
140-
verbose: bool = False, # noqa: FBT002, FBT001
144+
verbose: bool = False,
141145
) -> dict[str, Any]:
142146
"""Run behavioral tests and return results in an LLM-friendly format.
143147
@@ -201,15 +205,11 @@ def run_behavioral_tests_tool(
201205
test_env=test_env,
202206
cwd=project_root_path,
203207
pytest_timeout=pytest_timeout,
204-
verbose=verbose,
205208
)
206209

207210
# Create test config for parsing results
208211
test_config = TestConfig(
209-
tests_root=project_root_path,
210-
project_root_path=project_root_path,
211-
test_framework=test_framework,
212-
tests_project_rootdir=project_root_path,
212+
tests_root=project_root_path, project_root_path=project_root_path, tests_project_rootdir=project_root_path
213213
)
214214

215215
# Parse test results
@@ -270,8 +270,13 @@ def run_behavioral_tests_tool(
270270
}
271271

272272

273+
class ToolEntry(TypedDict):
274+
schema: dict[str, Any]
275+
function: Callable[..., dict[str, Any]]
276+
277+
273278
# Registry of available tools
274-
AVAILABLE_TOOLS = {
279+
AVAILABLE_TOOLS: dict[str, ToolEntry] = {
275280
"run_behavioral_tests": {"schema": RUN_BEHAVIORAL_TESTS_TOOL_SCHEMA, "function": run_behavioral_tests_tool}
276281
}
277282

@@ -300,7 +305,7 @@ def get_all_tool_schemas() -> list[dict[str, Any]]:
300305
return [tool["schema"] for tool in AVAILABLE_TOOLS.values()]
301306

302307

303-
def execute_tool(tool_name: str, **kwargs: Any) -> dict[str, Any]: # noqa: ANN401
308+
def execute_tool(tool_name: str, **kwargs: Any) -> dict[str, Any]:
304309
"""Execute a tool by name with the given arguments.
305310
306311
Args:

tests/test_llm_tools.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@
1515
)
1616

1717

18-
def test_run_behavioral_tests_tool_schema_structure():
18+
def test_run_behavioral_tests_tool_schema_structure() -> None:
1919
"""Test that the tool schema has the correct structure."""
2020
schema = RUN_BEHAVIORAL_TESTS_TOOL_SCHEMA
2121

2222
assert schema["type"] == "function"
2323
assert "function" in schema
24-
assert schema["function"]["name"] == "run_behavioral_tests"
25-
assert "description" in schema["function"]
26-
assert "parameters" in schema["function"]
27-
28-
params = schema["function"]["parameters"]
24+
func = schema["function"]
25+
assert isinstance(func, dict)
26+
assert func["name"] == "run_behavioral_tests"
27+
assert "description" in func
28+
assert "parameters" in func
29+
30+
params = func["parameters"]
31+
assert isinstance(params, dict)
2932
assert params["type"] == "object"
3033
assert "test_files" in params["properties"]
3134
assert "project_root" in params["properties"]
@@ -34,7 +37,7 @@ def test_run_behavioral_tests_tool_schema_structure():
3437
assert "project_root" in params["required"]
3538

3639

37-
def test_get_tool_schema():
40+
def test_get_tool_schema() -> None:
3841
"""Test getting tool schema by name."""
3942
schema = get_tool_schema("run_behavioral_tests")
4043
assert schema is not None
@@ -44,7 +47,7 @@ def test_get_tool_schema():
4447
assert get_tool_schema("non_existent_tool") is None
4548

4649

47-
def test_get_all_tool_schemas():
50+
def test_get_all_tool_schemas() -> None:
4851
"""Test getting all tool schemas."""
4952
schemas = get_all_tool_schemas()
5053
assert isinstance(schemas, list)
@@ -55,7 +58,7 @@ def test_get_all_tool_schemas():
5558
assert "run_behavioral_tests" in names
5659

5760

58-
def test_available_tools_registry():
61+
def test_available_tools_registry() -> None:
5962
"""Test that the AVAILABLE_TOOLS registry has correct structure."""
6063
assert "run_behavioral_tests" in AVAILABLE_TOOLS
6164

@@ -65,13 +68,13 @@ def test_available_tools_registry():
6568
assert callable(tool["function"])
6669

6770

68-
def test_execute_tool_unknown_tool():
71+
def test_execute_tool_unknown_tool() -> None:
6972
"""Test that execute_tool raises ValueError for unknown tools."""
7073
with pytest.raises(ValueError, match="Unknown tool"):
7174
execute_tool("non_existent_tool")
7275

7376

74-
def test_run_behavioral_tests_tool_pytest():
77+
def test_run_behavioral_tests_tool_pytest() -> None:
7578
"""Test running pytest tests through the LLM tool."""
7679
test_code = """
7780
def add(a, b):
@@ -104,7 +107,7 @@ def test_add():
104107
assert isinstance(result["results"], list)
105108

106109

107-
def test_run_behavioral_tests_tool_failing_test():
110+
def test_run_behavioral_tests_tool_failing_test() -> None:
108111
"""Test running a failing test through the LLM tool."""
109112
test_code = """
110113
def test_failing():
@@ -128,7 +131,7 @@ def test_failing():
128131
assert result["failed_tests"] >= 1
129132

130133

131-
def test_run_behavioral_tests_tool_via_execute():
134+
def test_run_behavioral_tests_tool_via_execute() -> None:
132135
"""Test running tests through the execute_tool interface."""
133136
test_code = """
134137
def test_simple():
@@ -151,7 +154,7 @@ def test_simple():
151154
assert result["error"] is None
152155

153156

154-
def test_run_behavioral_tests_tool_invalid_path():
157+
def test_run_behavioral_tests_tool_invalid_path() -> None:
155158
"""Test handling of invalid test file path."""
156159
# Use repo root for project_root
157160
repo_root = Path(__file__).resolve().parent.parent
@@ -167,7 +170,7 @@ def test_run_behavioral_tests_tool_invalid_path():
167170
assert result["total_tests"] == 0
168171

169172

170-
def test_run_behavioral_tests_tool_with_test_type():
173+
def test_run_behavioral_tests_tool_with_test_type() -> None:
171174
"""Test specifying test type."""
172175
test_code = """
173176
def test_with_type():

0 commit comments

Comments
 (0)