Fix remaining linting errors to resolve CI failures

- Add ClassVar import to console_formatter.py for proper type annotation
- Fix loop variable override issues by renaming inner loop variables
- Rename ToolUsageErrorException to ToolUsageError for naming convention
- All linting errors in modified files now resolved

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2025-09-11 08:27:47 +00:00
parent e2f4ea3956
commit 7ff4062d4a
2 changed files with 18 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, ClassVar
from rich.console import Console
from rich.live import Live
@@ -16,7 +16,7 @@ class ConsoleFormatter:
current_flow_tree: Tree | None = None
current_method_branch: Tree | None = None
current_lite_agent_branch: Tree | None = None
tool_usage_counts: dict[str, int] = {}
tool_usage_counts: ClassVar[dict[str, int]] = {}
current_reasoning_branch: Tree | None = None # Track reasoning status
_live_paused: bool = False
current_llm_tool_tree: Tree | None = None
@@ -115,7 +115,7 @@ class ConsoleFormatter:
self._live.update(tree, refresh=True)
return # Nothing else to do
# Case 2: blank line while a live session is running ignore so we
# Case 2: blank line while a live session is running - ignore so we
# don't break the in-place rendering behaviour
if len(args) == 0 and self._live:
return
@@ -1596,9 +1596,9 @@ class ConsoleFormatter:
for child in branch_to_use.children:
if "Memory Retrieval" in str(child.label):
for child in child.children:
sources_branch = child
if "Sources Used" in str(child.label):
for inner_child in child.children:
sources_branch = inner_child
if "Sources Used" in str(inner_child.label):
sources_branch.add(f"{memory_type} ({query_time_ms:.2f}ms)")
break
else:
@@ -1629,9 +1629,9 @@ class ConsoleFormatter:
for child in branch_to_use.children:
if "Memory Retrieval" in str(child.label):
for child in child.children:
sources_branch = child
if "Sources Used" in str(child.label):
for inner_child in child.children:
sources_branch = inner_child
if "Sources Used" in str(inner_child.label):
sources_branch.add(f"{memory_type} - Error: {error}")
break
else:

View File

@@ -44,7 +44,7 @@ OPENAI_BIGGER_MODELS = [
]
class ToolUsageErrorException(Exception):
class ToolUsageError(Exception):
"""Exception raised for errors in the tool usage."""
def __init__(self, message: str) -> None:
@@ -107,7 +107,7 @@ class ToolUsage:
def use(
self, calling: ToolCalling | InstructorToolCalling, tool_string: str
) -> str:
if isinstance(calling, ToolUsageErrorException):
if isinstance(calling, ToolUsageError):
error = calling.message
if self.agent and self.agent.verbose:
self._printer.print(content=f"\n\n{error}\n", color="red")
@@ -252,7 +252,7 @@ class ToolUsage:
error_message = self._i18n.errors("tool_usage_exception").format(
error=e, tool=tool.name, tool_inputs=tool.description
)
error = ToolUsageErrorException(
error = ToolUsageError(
f"\n{error_message}.\nMoving on then. {self._i18n.slice('format').format(tool_names=self.tools_names)}"
).message
if self.task:
@@ -456,13 +456,13 @@ class ToolUsage:
)
tool_object = converter.to_pydantic()
if not isinstance(tool_object, (ToolCalling, InstructorToolCalling)):
raise ToolUsageErrorException("Failed to parse tool calling")
raise ToolUsageError("Failed to parse tool calling")
return tool_object
def _original_tool_calling(
self, tool_string: str, raise_error: bool = False
) -> ToolCalling | InstructorToolCalling | ToolUsageErrorException:
) -> ToolCalling | InstructorToolCalling | ToolUsageError:
tool_name = self.action.tool
tool = self._select_tool(tool_name)
try:
@@ -471,14 +471,14 @@ class ToolUsage:
except Exception:
if raise_error:
raise
return ToolUsageErrorException(
return ToolUsageError(
f"{self._i18n.errors('tool_arguments_error')}"
)
if not isinstance(arguments, dict):
if raise_error:
raise
return ToolUsageErrorException(
return ToolUsageError(
f"{self._i18n.errors('tool_arguments_error')}"
)
@@ -489,7 +489,7 @@ class ToolUsage:
def _tool_calling(
self, tool_string: str
) -> ToolCalling | InstructorToolCalling | ToolUsageErrorException:
) -> ToolCalling | InstructorToolCalling | ToolUsageError:
try:
try:
return self._original_tool_calling(tool_string, raise_error=True)
@@ -505,7 +505,7 @@ class ToolUsage:
self.task.increment_tools_errors()
if self.agent and self.agent.verbose:
self._printer.print(content=f"\n\n{e}\n", color="red")
return ToolUsageErrorException( # type: ignore # Incompatible return value type (got "ToolUsageErrorException", expected "ToolCalling | InstructorToolCalling")
return ToolUsageError( # type: ignore # Incompatible return value type (got "ToolUsageError", expected "ToolCalling | InstructorToolCalling")
f"{self._i18n.errors('tool_usage_error').format(error=e)}\nMoving on then. {self._i18n.slice('format').format(tool_names=self.tools_names)}"
)
return self._tool_calling(tool_string)