From 9beb0a7af330ed13c712f03886c97d3be66ebaa3 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 7 Aug 2023 10:07:55 +0200 Subject: [PATCH] Skip `:type:` annotations from docstring args documentation. --- platypush/plugins/inspect/_model.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/platypush/plugins/inspect/_model.py b/platypush/plugins/inspect/_model.py index 6bfa50d5e..f16c7bb71 100644 --- a/platypush/plugins/inspect/_model.py +++ b/platypush/plugins/inspect/_model.py @@ -34,6 +34,10 @@ class Model: SchemaParser, ] + _param_docstring_re = re.compile(r'^\s*:param ([^:]+):\s*(.*)') + _type_docstring_re = re.compile(r'^\s*:type ([^:]+):\s*(.*)') + _return_docstring_re = re.compile(r'^\s*:return:\s+(.*)') + def __init__( self, obj_type: type, @@ -106,7 +110,7 @@ class Model: return None, {} for line in docstring.split('\n'): - m = re.match(r'^\s*:param ([^:]+):\s*(.*)', line) + m = cls._param_docstring_re.match(line) if m: if cur_param: params[cur_param] = cur_param_docstring @@ -115,7 +119,16 @@ class Model: cur_param_docstring = m.group(2) continue - m = re.match(r'^\s*:return:\s+(.*)', line) + m = cls._type_docstring_re.match(line) + if m: + if cur_param: + cur_param_docstring += '\n**Type:** ' + m.group(2).strip() + params[cur_param] = cur_param_docstring + + cur_param = None + continue + + m = cls._return_docstring_re.match(line) if m: if cur_param: params[cur_param] = cur_param_docstring