mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 23:04:48 +08:00
Fix complex param parsing in docstrings.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user