From b9216f56ebb8b4aa91f9f2ac3ca165e06027c782 Mon Sep 17 00:00:00 2001 From: VisualDust Date: Sun, 26 Nov 2023 05:45:26 +0800 Subject: [PATCH] added param annotations for action dict sent to frontend --- neetbox/daemon/client/_action_agent.py | 20 +++++++++++++++----- tests/client/test.py | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/neetbox/daemon/client/_action_agent.py b/neetbox/daemon/client/_action_agent.py index e6d35dc2..67dad213 100644 --- a/neetbox/daemon/client/_action_agent.py +++ b/neetbox/daemon/client/_action_agent.py @@ -29,6 +29,20 @@ def __init__( self.argspec = inspect.getfullargspec(self.function) self.blocking = blocking + def get_props_dict(self): + # _arg_dict = { + # _arg_name: self.argspec.annotations.get(_arg_name, None) + # for _arg_name in self.argspec.args + # } + _arg_anno_dict = self.function.__annotations__ + _args = self.argspec.args + __arg_dict = {_arg_name: _arg_anno_dict.get(_arg_name, any).__name__ for _arg_name in _args} + return { + "description": self.description, + "args": __arg_dict, + "blocking": self.blocking, + } + def __call__(self, **argv): self.function(argv) # ignore blocking @@ -52,11 +66,7 @@ def get_action_dict(): action_names = _NeetActionManager.__ACTION_POOL.keys() for name in action_names: action: PackedAction = _NeetActionManager.__ACTION_POOL[name] - action_dict[name] = { - "description": action.description, - "args": action.argspec.args, - "blocking": action.blocking, - } + action_dict[name] = action.get_props_dict() return action_dict def eval_call(name: str, params: dict, callback: None): diff --git a/tests/client/test.py b/tests/client/test.py index 702f45db..0fd9eedf 100644 --- a/tests/client/test.py +++ b/tests/client/test.py @@ -29,7 +29,7 @@ def log_with_some_prefix(): @action(name="action-1") -def action_1(text): +def action_1(text: str): """take action 1 Args: