feat,fix(core,docs): 完善核心模块代码注释并添加架构改进文档
- 为 core 目录下主要模块 (models, context, creator, base_api, exchange, executor) 添加了详细的类和方法 Docstring。 - 新增 docs/架构改进.md 文件。
This commit is contained in:
@@ -24,17 +24,31 @@ T = TypeVar("T", bound=Union[dict, list, str, Any])
|
||||
|
||||
|
||||
class Exchange:
|
||||
"""
|
||||
变量交换器类。
|
||||
负责管理全局变量缓存,核心职能包括:
|
||||
1. Extract: 从响应结果中提取变量。
|
||||
2. Replace: 将数据中的变量占位符替换为实际值。
|
||||
"""
|
||||
def __init__(self, variable_cache: dict[str, Any]):
|
||||
"""
|
||||
初始化交换器。
|
||||
|
||||
Args:
|
||||
variable_cache: 初始变量缓存字典(引用传递,修改会影响源数据)。
|
||||
"""
|
||||
self._cache = variable_cache
|
||||
# 匹配标准变量 ${var},排除函数调用 ${func()}
|
||||
self.var_only_pattern = re.compile(r"^\$\{([a-zA-Z_]\w*)}$")
|
||||
|
||||
@property
|
||||
def global_vars(self) -> dict:
|
||||
"""获取当前全局变量缓存。"""
|
||||
return self._cache
|
||||
|
||||
@global_vars.setter
|
||||
def global_vars(self, global_vars: dict) -> None:
|
||||
"""设置全局变量缓存(通常用于上下文切换,如 ChainMap 合并)。"""
|
||||
self._cache = global_vars
|
||||
|
||||
def extract(self, resp: Any, var_name: str, attr: str, expr: str, index: int = 0):
|
||||
|
||||
Reference in New Issue
Block a user