From a8a394fab5a0ac7340d2bcff30096f588ff5a33e Mon Sep 17 00:00:00 2001 From: Aditya Chhabra Date: Tue, 28 Oct 2025 13:27:51 +0530 Subject: [PATCH] fix: fix rest of the mypy --strict and pylint errors --- src/cleveragents/agents/composite.py | 4 ++++ src/cleveragents/core/application.py | 3 +++ src/cleveragents/templates/graph_templates.py | 5 ++--- src/cleveragents/templates/inline_jinja_handler.py | 6 ++++-- src/cleveragents/templates/stream_templates.py | 5 ++--- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/cleveragents/agents/composite.py b/src/cleveragents/agents/composite.py index c17f4122..4f21dbf7 100644 --- a/src/cleveragents/agents/composite.py +++ b/src/cleveragents/agents/composite.py @@ -275,6 +275,10 @@ class CompositeAgent(Agent): # pylint: disable=too-many-instance-attributes else: graph = self.graphs[graph_name] + # Type guard to satisfy mypy --strict + if graph is None: + raise ExecutionError(f"Graph '{graph_name}' could not be loaded") + # Execute graph result = await graph.execute( {"messages": [{"role": "user", "content": message}], "metadata": context} diff --git a/src/cleveragents/core/application.py b/src/cleveragents/core/application.py index 420c784e..b5cb3aca 100644 --- a/src/cleveragents/core/application.py +++ b/src/cleveragents/core/application.py @@ -475,6 +475,9 @@ class ReactiveCleverAgentsApp: # pylint: disable=too-many-instance-attributes ) else: # Use regular registration + # Type guard to satisfy mypy --strict + if self.template_registry is None: + raise CleverAgentsException("Template registry not initialized") self.template_registry.register_all_templates(self.config.templates) templates = self.config.templates or {} diff --git a/src/cleveragents/templates/graph_templates.py b/src/cleveragents/templates/graph_templates.py index 8a234708..7e1fbfc9 100644 --- a/src/cleveragents/templates/graph_templates.py +++ b/src/cleveragents/templates/graph_templates.py @@ -8,7 +8,6 @@ from typing import TYPE_CHECKING from typing import Any from typing import Dict from typing import List -from typing import cast from cleveragents.templates.base import BaseTemplate from cleveragents.templates.base import ComponentReference @@ -33,7 +32,7 @@ class GraphTemplate(BaseTemplate): filled_params = self.validate_params(params) # Deep copy the definition - graph_def = copy.deepcopy(self.definition) + graph_def: Dict[str, Any] = copy.deepcopy(self.definition) # Remove parameters section if "parameters" in graph_def: @@ -56,7 +55,7 @@ class GraphTemplate(BaseTemplate): if "name" not in graph_def: graph_def["name"] = self.name - return cast(Dict[str, Any], graph_def) + return graph_def def _process_nodes( self, diff --git a/src/cleveragents/templates/inline_jinja_handler.py b/src/cleveragents/templates/inline_jinja_handler.py index 742b5e24..995caacd 100644 --- a/src/cleveragents/templates/inline_jinja_handler.py +++ b/src/cleveragents/templates/inline_jinja_handler.py @@ -277,9 +277,11 @@ class InlineJinjaHandler: result = {k: v for k, v in config.items() if k != "__templates__"} # Apply templates recursively - result = self._apply_templates_recursive(result, templates, context) + result_with_templates: Dict[str, Any] = self._apply_templates_recursive( + result, templates, context + ) - return cast(Dict[str, Any], result) + return result_with_templates def _apply_templates_recursive( # pylint: disable=too-many-nested-blocks self, data: Any, templates: Dict[str, Any], context: Dict[str, Any] diff --git a/src/cleveragents/templates/stream_templates.py b/src/cleveragents/templates/stream_templates.py index 06e94d3d..f5bfbc68 100644 --- a/src/cleveragents/templates/stream_templates.py +++ b/src/cleveragents/templates/stream_templates.py @@ -8,7 +8,6 @@ from typing import TYPE_CHECKING from typing import Any from typing import Dict from typing import List -from typing import cast from cleveragents.templates.base import BaseTemplate from cleveragents.templates.base import ComponentReference @@ -33,7 +32,7 @@ class StreamTemplate(BaseTemplate): filled_params = self.validate_params(params) # Deep copy the definition - stream_def = copy.deepcopy(self.definition) + stream_def: Dict[str, Any] = copy.deepcopy(self.definition) # Remove parameters section if "parameters" in stream_def: @@ -52,7 +51,7 @@ class StreamTemplate(BaseTemplate): if "name" not in stream_def: stream_def["name"] = self.name - return cast(Dict[str, Any], stream_def) + return stream_def def _process_operators( # pylint: disable=too-many-branches self, operators: List[Any], params: Dict[str, Any], context: InstantiationContext