forked from VimPlug/jedi
Merge pull request #96 from jjay/improvedocparse
Improve docstring parsing for param types.
This commit is contained in:
+6
-14
@@ -6,19 +6,13 @@ 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
|
||||
r'\s*:type\s+%s:\s*([^\n]+)', # Sphinx
|
||||
r'\s*@type\s+%s:\s*([^\n]+)', # Epidoc
|
||||
]
|
||||
|
||||
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
|
||||
@@ -35,14 +29,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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user