From a1624acc0863ab0699bafb693c017d2548f13d6e Mon Sep 17 00:00:00 2001 From: QuantumGhost Date: Mon, 23 Jun 2025 14:25:52 +0800 Subject: [PATCH] chore(api): fix mypy violations --- .../nodes/variable_aggregator/variable_aggregator_node.py | 5 ++++- api/core/workflow/nodes/variable_assigner/v2/node.py | 5 +++-- api/models/workflow.py | 1 + api/services/workflow_service.py | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/api/core/workflow/nodes/variable_aggregator/variable_aggregator_node.py b/api/core/workflow/nodes/variable_aggregator/variable_aggregator_node.py index 167805c6ff..96bb3e793a 100644 --- a/api/core/workflow/nodes/variable_aggregator/variable_aggregator_node.py +++ b/api/core/workflow/nodes/variable_aggregator/variable_aggregator_node.py @@ -1,3 +1,6 @@ +from collections.abc import Mapping + +from core.variables.segments import Segment from core.workflow.entities.node_entities import NodeRunResult from core.workflow.entities.workflow_node_execution import WorkflowNodeExecutionStatus from core.workflow.nodes.base import BaseNode @@ -15,7 +18,7 @@ class VariableAggregatorNode(BaseNode[VariableAssignerNodeData]): def _run(self) -> NodeRunResult: # Get variables - outputs = {} + outputs: dict[str, Segment | Mapping[str, Segment]] = {} inputs = {} if not self.node_data.advanced_settings or not self.node_data.advanced_settings.group_enabled: diff --git a/api/core/workflow/nodes/variable_assigner/v2/node.py b/api/core/workflow/nodes/variable_assigner/v2/node.py index 1804316a31..9292da6f1c 100644 --- a/api/core/workflow/nodes/variable_assigner/v2/node.py +++ b/api/core/workflow/nodes/variable_assigner/v2/node.py @@ -1,6 +1,6 @@ import json from collections.abc import Callable, Mapping, MutableMapping, Sequence -from typing import Any, ClassVar, TypeAlias, cast +from typing import Any, TypeAlias, cast from core.app.entities.app_invoke_entities import InvokeFrom from core.variables import SegmentType, Variable @@ -58,7 +58,8 @@ class VariableAssignerNode(BaseNode[VariableAssignerNodeData]): _node_data_cls = VariableAssignerNodeData _node_type = NodeType.VARIABLE_ASSIGNER - _conv_var_updater_factory: ClassVar[_CONV_VAR_UPDATER_FACTORY] = staticmethod(conversation_variable_updater_factory) + def _conv_var_updater_factory(self) -> ConversationVariableUpdater: + return conversation_variable_updater_factory() @classmethod def version(cls) -> str: diff --git a/api/models/workflow.py b/api/models/workflow.py index fe433ae1a7..df515836d0 100644 --- a/api/models/workflow.py +++ b/api/models/workflow.py @@ -229,6 +229,7 @@ class Workflow(Base): node_config = next(filter(lambda node: node["id"] == node_id, nodes)) except StopIteration: raise NodeNotFoundError(node_id) + assert isinstance(node_config, dict) return node_config @staticmethod diff --git a/api/services/workflow_service.py b/api/services/workflow_service.py index d52e4302ef..0fd94ac86e 100644 --- a/api/services/workflow_service.py +++ b/api/services/workflow_service.py @@ -674,7 +674,7 @@ def _setup_variable_pool( # Only inject system variables for START node type. if node_type == NodeType.START: # Create a variable pool. - system_inputs = { + system_inputs: dict[SystemVariableKey, Any] = { # From inputs: SystemVariableKey.FILES: files, SystemVariableKey.USER_ID: user_id,