From c7cf7b6dc73b442583c71cfbf6b52e15fdcbd31e Mon Sep 17 00:00:00 2001 From: Yakov Borevich Date: Fri, 28 Dec 2012 09:21:06 +0400 Subject: [PATCH 1/2] Fix complex param parsing in docstrings. --- jedi/docstrings.py | 14 ++++++-------- test/completion/docstring.py | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/jedi/docstrings.py b/jedi/docstrings.py index 043c7c1b..79d20246 100644 --- a/jedi/docstrings.py +++ b/jedi/docstrings.py @@ -6,8 +6,8 @@ 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*:type\s+%s:\s*([^\n]+)', # Sphinx + r'\s*@type\s+%s:\s*([^\n]+)', # Epidoc r'\s*%s\s+\(([^()]+)\)' # googley ] @@ -35,14 +35,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 patterns = [ re.compile(p % re.escape(param_str)) for p in DOCSTRING_PARAM_PATTERNS ] - for l in lines: - for pattern in patterns: - match = pattern.match(l) - if match: - return match.group(1) + for pattern in patterns: + match = pattern.search(docstr) + if match: + return match.group(1) return None diff --git a/test/completion/docstring.py b/test/completion/docstring.py index 5b9af186..202461ec 100644 --- a/test/completion/docstring.py +++ b/test/completion/docstring.py @@ -4,12 +4,15 @@ def f(a, b): """ asdfasdf :param a: blablabla :type a: str + :type b: (str, int) :rtype: dict """ #? str() a - #? - b + #? str() + b[0] + #? int() + b[1] #? dict() f() @@ -34,12 +37,17 @@ def e(a, b): """ asdfasdf @type a: str @param a: blablabla + @type b: (str, int) + @param b: blablah @rtype: list """ #? str() a - #? - b + #? str() + b[0] + + #? int() + b[1] #? list() e() From 3b412c72e903adc25e1ecad82f96769b0afa1ff1 Mon Sep 17 00:00:00 2001 From: Yakov Borevich Date: Fri, 28 Dec 2012 10:08:16 +0400 Subject: [PATCH 2/2] Remove google docstrings support. Updates #40 --- jedi/docstrings.py | 6 ------ test/completion/docstring.py | 16 ---------------- test/completion/std.py | 5 ++++- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/jedi/docstrings.py b/jedi/docstrings.py index 79d20246..39134b19 100644 --- a/jedi/docstrings.py +++ b/jedi/docstrings.py @@ -8,17 +8,11 @@ import parsing DOCSTRING_PARAM_PATTERNS = [ r'\s*:type\s+%s:\s*([^\n]+)', # Sphinx r'\s*@type\s+%s:\s*([^\n]+)', # Epidoc - r'\s*%s\s+\(([^()]+)\)' # googley ] DOCSTRING_RETURN_PATTERNS = [ re.compile(r'\s*:rtype:\s*([^\n]+)', re.M), # Sphinx re.compile(r'\s*@rtype:\s*([^\n]+)', re.M), # Epidoc - - # Googley is the most undocumented format for - # return types, so we try to analyze the first - # line or line after `Returns:` keyword - re.compile(r'returns\s*:[\s\n]*([^\n]+)', re.M|re.I), ] #@cache.memoize_default() # TODO add diff --git a/test/completion/docstring.py b/test/completion/docstring.py index 202461ec..66b6744e 100644 --- a/test/completion/docstring.py +++ b/test/completion/docstring.py @@ -17,22 +17,6 @@ def f(a, b): #? dict() f() -def g(a, b): - """ asdfasdf - Arguments: - a (str): blablabla - - Returns: list - Blah blah. - """ - #? str() - a - #? - b - -#? list() -g() - def e(a, b): """ asdfasdf @type a: str diff --git a/test/completion/std.py b/test/completion/std.py index 6ea57f30..0eec6367 100644 --- a/test/completion/std.py +++ b/test/completion/std.py @@ -83,7 +83,10 @@ row = c.fetchall()[0] row.keys()[0] def huhu(db): - """db (sqlite3.Connection): the db connection""" + """ + :type db: sqlite3.Connection + :param db: the db connection + """ #? sqlite3.Connection() db