mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-11 09:08:43 +08:00
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
|
import parsing
|
||||||
|
|
||||||
DOCSTRING_PARAM_PATTERNS = [
|
DOCSTRING_PARAM_PATTERNS = [
|
||||||
r'\s*:type\s+%s:\s*([\d\w_]+)', # Sphinx
|
r'\s*:type\s+%s:\s*([^\n]+)', # Sphinx
|
||||||
r'\s*@type\s+%s:\s*([\d\w_]+)', # Epidoc
|
r'\s*@type\s+%s:\s*([^\n]+)', # Epidoc
|
||||||
r'\s*%s\s+\(([^()]+)\)' # googley
|
|
||||||
]
|
]
|
||||||
|
|
||||||
DOCSTRING_RETURN_PATTERNS = [
|
DOCSTRING_RETURN_PATTERNS = [
|
||||||
re.compile(r'\s*:rtype:\s*([^\n]+)', re.M), # Sphinx
|
re.compile(r'\s*:rtype:\s*([^\n]+)', re.M), # Sphinx
|
||||||
re.compile(r'\s*@rtype:\s*([^\n]+)', re.M), # Epidoc
|
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
|
#@cache.memoize_default() # TODO add
|
||||||
@@ -35,14 +29,12 @@ def follow_param(param):
|
|||||||
|
|
||||||
|
|
||||||
def search_param_in_docstr(docstr, param_str):
|
def search_param_in_docstr(docstr, param_str):
|
||||||
lines = docstr.split('\n')
|
|
||||||
# look at #40 to see definitions of those params
|
# look at #40 to see definitions of those params
|
||||||
patterns = [ re.compile(p % re.escape(param_str)) for p in DOCSTRING_PARAM_PATTERNS ]
|
patterns = [ re.compile(p % re.escape(param_str)) for p in DOCSTRING_PARAM_PATTERNS ]
|
||||||
for l in lines:
|
for pattern in patterns:
|
||||||
for pattern in patterns:
|
match = pattern.search(docstr)
|
||||||
match = pattern.match(l)
|
if match:
|
||||||
if match:
|
return match.group(1)
|
||||||
return match.group(1)
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -4,42 +4,34 @@ def f(a, b):
|
|||||||
""" asdfasdf
|
""" asdfasdf
|
||||||
:param a: blablabla
|
:param a: blablabla
|
||||||
:type a: str
|
:type a: str
|
||||||
|
:type b: (str, int)
|
||||||
:rtype: dict
|
:rtype: dict
|
||||||
"""
|
"""
|
||||||
#? str()
|
#? str()
|
||||||
a
|
a
|
||||||
#?
|
#? str()
|
||||||
b
|
b[0]
|
||||||
|
#? int()
|
||||||
|
b[1]
|
||||||
|
|
||||||
#? dict()
|
#? dict()
|
||||||
f()
|
f()
|
||||||
|
|
||||||
def g(a, b):
|
|
||||||
""" asdfasdf
|
|
||||||
Arguments:
|
|
||||||
a (str): blablabla
|
|
||||||
|
|
||||||
Returns: list
|
|
||||||
Blah blah.
|
|
||||||
"""
|
|
||||||
#? str()
|
|
||||||
a
|
|
||||||
#?
|
|
||||||
b
|
|
||||||
|
|
||||||
#? list()
|
|
||||||
g()
|
|
||||||
|
|
||||||
def e(a, b):
|
def e(a, b):
|
||||||
""" asdfasdf
|
""" asdfasdf
|
||||||
@type a: str
|
@type a: str
|
||||||
@param a: blablabla
|
@param a: blablabla
|
||||||
|
@type b: (str, int)
|
||||||
|
@param b: blablah
|
||||||
@rtype: list
|
@rtype: list
|
||||||
"""
|
"""
|
||||||
#? str()
|
#? str()
|
||||||
a
|
a
|
||||||
#?
|
#? str()
|
||||||
b
|
b[0]
|
||||||
|
|
||||||
|
#? int()
|
||||||
|
b[1]
|
||||||
|
|
||||||
#? list()
|
#? list()
|
||||||
e()
|
e()
|
||||||
|
|||||||
@@ -83,7 +83,10 @@ row = c.fetchall()[0]
|
|||||||
row.keys()[0]
|
row.keys()[0]
|
||||||
|
|
||||||
def huhu(db):
|
def huhu(db):
|
||||||
"""db (sqlite3.Connection): the db connection"""
|
"""
|
||||||
|
:type db: sqlite3.Connection
|
||||||
|
:param db: the db connection
|
||||||
|
"""
|
||||||
#? sqlite3.Connection()
|
#? sqlite3.Connection()
|
||||||
db
|
db
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user