From bbf76d0e42f83a0297b3fcd57ca1ac109c94bcf2 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 10 Sep 2025 01:58:41 +0000 Subject: [PATCH] Fix CI issues: type-checker, lint errors (S101, RET504, B904) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add type ignore for create_model call to fix type-checker error - Fix exception chaining (B904) by using 'from e' syntax - Fix unnecessary assignment (RET504) by returning directly - Add noqa comments for S101 assert detection in test file Co-Authored-By: João --- src/crewai/tools/structured_tool.py | 9 ++++----- tests/tools/test_structured_tool.py | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/crewai/tools/structured_tool.py b/src/crewai/tools/structured_tool.py index d4b1b5cfe..5cbe15899 100644 --- a/src/crewai/tools/structured_tool.py +++ b/src/crewai/tools/structured_tool.py @@ -164,7 +164,7 @@ class CrewStructuredTool: # Create model schema_name = f"{name.title()}Schema" - return create_model(schema_name, **fields) + return create_model(schema_name, **fields) # type: ignore[call-overload] def _validate_function_signature(self) -> None: """Validate that the function signature matches the args schema.""" @@ -207,13 +207,13 @@ class CrewStructuredTool: raw_args = json.loads(raw_args) except json.JSONDecodeError as e: - raise ValueError(f"Failed to parse arguments as JSON: {e}") + raise ValueError(f"Failed to parse arguments as JSON: {e}") from e try: validated_args = self.args_schema.model_validate(raw_args) return validated_args.model_dump() except Exception as e: - raise ValueError(f"Arguments validation failed: {e}") + raise ValueError(f"Arguments validation failed: {e}") from e async def ainvoke( self, @@ -274,8 +274,7 @@ class CrewStructuredTool: self._increment_usage_count() if inspect.iscoroutinefunction(self.func): - result = asyncio.run(self.func(**parsed_args, **kwargs)) - return result + return asyncio.run(self.func(**parsed_args, **kwargs)) try: result = self.func(**parsed_args, **kwargs) diff --git a/tests/tools/test_structured_tool.py b/tests/tools/test_structured_tool.py index 7eb00540d..a53bba80e 100644 --- a/tests/tools/test_structured_tool.py +++ b/tests/tools/test_structured_tool.py @@ -163,12 +163,12 @@ def test_tool_not_executed_twice(): result = tool.invoke({"param": "test"}) - assert call_count == 1, f"Expected function to be called once, but was called {call_count} times" - assert result == "Called 1 times with test" + assert call_count == 1, f"Expected function to be called once, but was called {call_count} times" # noqa: S101 + assert result == "Called 1 times with test" # noqa: S101 result = tool.invoke({"param": "test2"}) - assert call_count == 2, f"Expected function to be called twice total, but was called {call_count} times" - assert result == "Called 2 times with test2" + assert call_count == 2, f"Expected function to be called twice total, but was called {call_count} times" # noqa: S101 + assert result == "Called 2 times with test2" # noqa: S101 @pytest.fixture def custom_tool_decorator():