ActionFunc 签名不一致:concurrent_tasks 的 args 传参与标准签名冲突 #39
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
问题描述
ActionFunc类型签名定义为Callable[[dict], Any](compiler.py:16),即 action 函数只接受一个context参数。但
_periodic_runner(compiler.py:155-158)中调用 action 时传入了额外参数:这意味着如果 DSL 中
concurrent_tasks的args非空,action 函数会被调用为action(context, arg1, arg2, ...),与ActionFunc声明的(dict) -> Any签名不一致。影响
on_enter(无参调用)和concurrent_tasks(带参调用),函数内部无法感知额外的 args,传参静默丢失现状
目前项目中没有实际使用
concurrent_tasks.args的案例,所以是理论问题而非运行时 bug——但这是一个潜在陷阱,新开发者踩中概率高。建议方案
方案 A(推荐):将 args 通过 context 传递,保持签名统一
action 函数按需从
context["_task_args"]中读取参数。方案 B:明确区分两种签名
方案 C:只使用
task_spec.args做 context 注入(如context.setdefault("_task_args", []).extend(resolved_args)),不传*args