From 38096ad319551bd3dd3facb5cfbb73c9ba2299cb Mon Sep 17 00:00:00 2001 From: Rick van Hattem Date: Thu, 13 Aug 2015 13:15:41 +0200 Subject: [PATCH] added google/napoleon docstring support to fix #504 --- jedi/evaluate/docstrings.py | 6 ++++++ test/completion/docstring.py | 38 +++++++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/jedi/evaluate/docstrings.py b/jedi/evaluate/docstrings.py index d2ab34ed1..aaa2b420b 100644 --- a/jedi/evaluate/docstrings.py +++ b/jedi/evaluate/docstrings.py @@ -30,11 +30,13 @@ r'\s*:type\s+%s:\s*([^\n]+)', # Sphinx r'\s*:param\s+(\w+)\s+%s:[^\n]+', # Sphinx param with type r'\s*@type\s+%s:\s*([^\n]+)', # Epydoc + '\s*%s\s*\((.+?)\):.+', # Google param with type ] DOCSTRING_RETURN_PATTERNS = [ re.compile(r'\s*:rtype:\s*([^\n]+)', re.M), # Sphinx re.compile(r'\s*@rtype:\s*([^\n]+)', re.M), # Epydoc + re.compile(r'\s*Returns:\s*([^:]+):.*', re.M), # Google ] REST_ROLE_PATTERN = re.compile(r':[^`]+:`([^`]+)`') @@ -78,6 +80,10 @@ def _search_param_in_docstr(docstr, param_str): False >>> _search_param_in_docstr(':param int param: some description', 'param') ['int'] + >>> _search_param_in_docstr('param (int): doc', 'param') + ['int'] + >>> _search_param_in_docstr('param: doc', 'param') + [] """ # look at #40 to see definitions of those params diff --git a/test/completion/docstring.py b/test/completion/docstring.py index 338080a4e..4b34e43b0 100644 --- a/test/completion/docstring.py +++ b/test/completion/docstring.py @@ -39,16 +39,48 @@ def sphinxy2(a, b, x): :param x: Just something without type :rtype: """ - #? + #? a - #? + #? b #? x -#? +#? sphinxy2() +# ----------------- +# google style +# ----------------- +def sphinx_google(a, b, c, d, x): + """ asdfasdf + + Args: + a (str): blablabla + b (str, int): b + c (random.Random): c + d (random.Random): d + x: blablabla + + Returns: + dict: Some dict + """ + #? str() + a + #? str() + b[0] + #? int() + b[1] + #? ['seed'] + c.seed + #? ['seed'] + d.seed + #? + x.lower + +#? dict() +sphinx_google() + # local classes -> github #370 class ProgramNode(): pass