Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

typevar example (#25064)

Asuka Minato462e764a3c0e
diff --git a/api/core/helper/position_helper.py b/api/core/helper/position_helper.py
index 8def6fe4ed5..314f052832a 100644
--- a/api/core/helper/position_helper.py
+++ b/api/core/helper/position_helper.py
@@ -1,7 +1,7 @@
import os
from collections import OrderedDict
from collections.abc import Callable
-from typing import Any
+from typing import TypeVar
from configs import dify_config
from core.tools.utils.yaml_utils import load_yaml_file
@@ -72,11 +72,14 @@ def pin_position_map(original_position_map: dict[str, int], pin_list: list[str])
return position_map
+T = TypeVar("T")
+
+
def is_filtered(
include_set: set[str],
exclude_set: set[str],
- data: Any,
- name_func: Callable[[Any], str],
+ data: T,
+ name_func: Callable[[T], str],
) -> bool:
"""
Check if the object should be filtered out.
@@ -103,9 +106,9 @@ def is_filtered(
def sort_by_position_map(
position_map: dict[str, int],
- data: list[Any],
- name_func: Callable[[Any], str],
-) -> list[Any]:
+ data: list[T],
+ name_func: Callable[[T], str],
+):
"""
Sort the objects by the position map.
If the name of the object is not in the position map, it will be put at the end.
@@ -122,9 +125,9 @@ def sort_by_position_map(
def sort_to_dict_by_position_map(
position_map: dict[str, int],
- data: list[Any],
- name_func: Callable[[Any], str],
-) -> OrderedDict[str, Any]:
+ data: list[T],
+ name_func: Callable[[T], str],
+):
"""
Sort the objects into a ordered dict by the position map.
If the name of the object is not in the position map, it will be put at the end.
@@ -134,4 +137,4 @@ def sort_to_dict_by_position_map(
:return: an OrderedDict with the sorted pairs of name and object
"""
sorted_items = sort_by_position_map(position_map, data, name_func)
- return OrderedDict([(name_func(item), item) for item in sorted_items])
+ return OrderedDict((name_func(item), item) for item in sorted_items)