From 46a3ecc7d894f9b6c90653a308b17c32b73c4a58 Mon Sep 17 00:00:00 2001 From: Yakov Borevich Date: Wed, 26 Dec 2012 21:18:06 +0400 Subject: [PATCH 1/2] Support for Epydoc format in docstrings --- jedi/docstrings.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/jedi/docstrings.py b/jedi/docstrings.py index 63f83f34..4d3280af 100644 --- a/jedi/docstrings.py +++ b/jedi/docstrings.py @@ -5,6 +5,11 @@ import re import evaluate import parsing +DOCSTRING_PARAM_PATTERNS = [ + r'\s*:type\s+%s:\s*([\d\w_]+)', # Sphinx + r'\s*@type\s+%s:\s*([\d\w_]+)', # Epidoc + r'\s*%s\s+\(([^()]+)\)' # googley +] #@cache.memoize_default() # TODO add def follow_param(param): @@ -21,15 +26,12 @@ def follow_param(param): def search_param_in_docstr(docstr, param_str): lines = docstr.split('\n') - # look at #40 to see definitions of those params - sphinx_comp = ':type %s:' % param_str - googley_comp = re.compile('\s*%s\s+\(([^()]+)\)' % re.escape(param_str)) + patterns = [ re.compile(p % re.escape(param_str)) for p in DOCSTRING_PARAM_PATTERNS ] for l in lines: - if l.startswith(sphinx_comp): - return l.replace(sphinx_comp, '', 1).strip() + for pattern in patterns: + match = pattern.match(l) + if match: + return match.group(1) - r = re.match(googley_comp, l) - if r is not None: - return r.group(1) return None From a7f7d8ff9f8279ec2c1f3981b1507001f1f94394 Mon Sep 17 00:00:00 2001 From: Yakov Borevich Date: Thu, 27 Dec 2012 14:41:29 +0400 Subject: [PATCH 2/2] Add tests for epydoc formated dosctring --- test/completion/docstring.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/completion/docstring.py b/test/completion/docstring.py index 8362630b..29bc4c7d 100644 --- a/test/completion/docstring.py +++ b/test/completion/docstring.py @@ -19,3 +19,13 @@ def g(a, b): a #? b + +def e(a, b): + """ asdfasdf + @type a: str + @param a: blablabla + """ + #? str() + a + #? + b