Skip to content

Commit

Permalink
added param annotations for action dict sent to frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
visualDust committed Nov 25, 2023
1 parent 2871ad4 commit b9216f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions neetbox/daemon/client/_action_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/client/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b9216f5

Please sign in to comment.