From b91c1eba6df93f6638d6a9ce20d143bafebb908e Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 21 May 2023 03:05:19 +0200 Subject: [PATCH] Parse `:return:` definitions from action docstrings too. --- platypush/plugins/inspect/_model.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/platypush/plugins/inspect/_model.py b/platypush/plugins/inspect/_model.py index d0f82abf8c..be73783fcd 100644 --- a/platypush/plugins/inspect/_model.py +++ b/platypush/plugins/inspect/_model.py @@ -152,13 +152,18 @@ class ActionModel(Model): return None, {} for line in docstring.split('\n'): - m = re.match(r'^\s*:param ([^:]+):\s*(.*)', line) - if m: + if m := re.match(r'^\s*:param ([^:]+):\s*(.*)', line): if cur_param: params[cur_param] = cur_param_docstring cur_param = m.group(1) cur_param_docstring = m.group(2) + elif m := re.match(r'^\s*:return:\s+(.*)', line): + if cur_param: + params[cur_param] = cur_param_docstring + + new_docstring += '\n\n**Returns:**\n\n' + m.group(1).strip() + ' ' + cur_param = None elif re.match(r'^\s*:[^:]+:\s*.*', line): continue else: @@ -168,9 +173,9 @@ class ActionModel(Model): cur_param = None cur_param_docstring = '' else: - cur_param_docstring += '\n' + line.strip() + cur_param_docstring += '\n' + line.strip() + ' ' else: - new_docstring += line.rstrip() + '\n' + new_docstring += line.strip() + ' ' if cur_param: params[cur_param] = cur_param_docstring