mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 17:39:06 +08:00
fix(code_node): update type hints for string and number checks in Cod… (#11936)
Signed-off-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
parent
599d410d99
commit
a227af3664
@ -1,5 +1,5 @@
|
|||||||
from collections.abc import Mapping, Sequence
|
from collections.abc import Mapping, Sequence
|
||||||
from typing import Any, Optional, Union
|
from typing import Any, Optional
|
||||||
|
|
||||||
from configs import dify_config
|
from configs import dify_config
|
||||||
from core.helper.code_executor.code_executor import CodeExecutionError, CodeExecutor, CodeLanguage
|
from core.helper.code_executor.code_executor import CodeExecutionError, CodeExecutor, CodeLanguage
|
||||||
@ -67,17 +67,16 @@ class CodeNode(BaseNode[CodeNodeData]):
|
|||||||
|
|
||||||
return NodeRunResult(status=WorkflowNodeExecutionStatus.SUCCEEDED, inputs=variables, outputs=result)
|
return NodeRunResult(status=WorkflowNodeExecutionStatus.SUCCEEDED, inputs=variables, outputs=result)
|
||||||
|
|
||||||
def _check_string(self, value: str, variable: str) -> str:
|
def _check_string(self, value: str | None, variable: str) -> str | None:
|
||||||
"""
|
"""
|
||||||
Check string
|
Check string
|
||||||
:param value: value
|
:param value: value
|
||||||
:param variable: variable
|
:param variable: variable
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
if not isinstance(value, str):
|
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
else:
|
if not isinstance(value, str):
|
||||||
raise OutputValidationError(f"Output variable `{variable}` must be a string")
|
raise OutputValidationError(f"Output variable `{variable}` must be a string")
|
||||||
|
|
||||||
if len(value) > dify_config.CODE_MAX_STRING_LENGTH:
|
if len(value) > dify_config.CODE_MAX_STRING_LENGTH:
|
||||||
@ -88,17 +87,16 @@ class CodeNode(BaseNode[CodeNodeData]):
|
|||||||
|
|
||||||
return value.replace("\x00", "")
|
return value.replace("\x00", "")
|
||||||
|
|
||||||
def _check_number(self, value: Union[int, float], variable: str) -> Union[int, float]:
|
def _check_number(self, value: int | float | None, variable: str) -> int | float | None:
|
||||||
"""
|
"""
|
||||||
Check number
|
Check number
|
||||||
:param value: value
|
:param value: value
|
||||||
:param variable: variable
|
:param variable: variable
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
if not isinstance(value, int | float):
|
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
else:
|
if not isinstance(value, int | float):
|
||||||
raise OutputValidationError(f"Output variable `{variable}` must be a number")
|
raise OutputValidationError(f"Output variable `{variable}` must be a number")
|
||||||
|
|
||||||
if value > dify_config.CODE_MAX_NUMBER or value < dify_config.CODE_MIN_NUMBER:
|
if value > dify_config.CODE_MAX_NUMBER or value < dify_config.CODE_MIN_NUMBER:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user