forked from VimPlug/jedi
clean up _parse_function_doc a little bit, #298
This commit is contained in:
@@ -347,6 +347,9 @@ def _parse_function_doc(func):
|
|||||||
# TODO: things like utime(path, (atime, mtime)) and a(b [, b]) -> None
|
# TODO: things like utime(path, (atime, mtime)) and a(b [, b]) -> None
|
||||||
doc = inspect.getdoc(func)
|
doc = inspect.getdoc(func)
|
||||||
|
|
||||||
|
if doc is None:
|
||||||
|
return '', 'pass'
|
||||||
|
|
||||||
# get full string, parse round parentheses: def func(a, (b,c))
|
# get full string, parse round parentheses: def func(a, (b,c))
|
||||||
try:
|
try:
|
||||||
count = 0
|
count = 0
|
||||||
@@ -361,7 +364,13 @@ def _parse_function_doc(func):
|
|||||||
end = start + i
|
end = start + i
|
||||||
break
|
break
|
||||||
param_str = doc[start + 1:end]
|
param_str = doc[start + 1:end]
|
||||||
|
except (ValueError, UnboundLocalError):
|
||||||
|
# ValueError for doc.index
|
||||||
|
# UnboundLocalError for undefined end in last line
|
||||||
|
debug.dbg('no brackets found - no param')
|
||||||
|
end = 0
|
||||||
|
param_str = ''
|
||||||
|
else:
|
||||||
# remove square brackets, that show an optional param ( = None)
|
# remove square brackets, that show an optional param ( = None)
|
||||||
def change_options(m):
|
def change_options(m):
|
||||||
args = m.group(1).split(',')
|
args = m.group(1).split(',')
|
||||||
@@ -369,22 +378,18 @@ def _parse_function_doc(func):
|
|||||||
if a and '=' not in a:
|
if a and '=' not in a:
|
||||||
args[i] += '=None'
|
args[i] += '=None'
|
||||||
return ','.join(args)
|
return ','.join(args)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
param_str, changes = re.subn(r' ?\[([^\[\]]+)\]',
|
param_str, changes = re.subn(r' ?\[([^\[\]]+)\]',
|
||||||
change_options, param_str)
|
change_options, param_str)
|
||||||
if changes == 0:
|
if changes == 0:
|
||||||
break
|
break
|
||||||
except (ValueError, AttributeError, UnboundLocalError):
|
|
||||||
debug.dbg('no brackets found - no param')
|
|
||||||
end = 0
|
|
||||||
param_str = ''
|
|
||||||
|
|
||||||
param_str = param_str.replace('-', '_') # see: isinstance.__doc__
|
param_str = param_str.replace('-', '_') # see: isinstance.__doc__
|
||||||
|
|
||||||
if doc is not None:
|
# parse return value
|
||||||
r = re.search('-[>-]* ', doc[end:end + 7])
|
r = re.search('-[>-]* ', doc[end:end + 7])
|
||||||
if doc is None or r is None:
|
if r is None:
|
||||||
ret = 'pass' if doc is None else ''
|
ret = ''
|
||||||
else:
|
else:
|
||||||
index = end + r.end()
|
index = end + r.end()
|
||||||
# get result type, which can contain newlines
|
# get result type, which can contain newlines
|
||||||
@@ -396,7 +401,7 @@ def _parse_function_doc(func):
|
|||||||
ret = BuiltinModule.map_types.get(ret_str, ret_str)
|
ret = BuiltinModule.map_types.get(ret_str, ret_str)
|
||||||
if ret == ret_str and ret not in ['None', 'object', 'tuple', 'set']:
|
if ret == ret_str and ret not in ['None', 'object', 'tuple', 'set']:
|
||||||
debug.dbg('not working', ret_str)
|
debug.dbg('not working', ret_str)
|
||||||
if ret != 'pass':
|
|
||||||
ret = ('return ' if 'return' not in ret else '') + ret
|
ret = ('return ' if 'return' not in ret else '') + ret
|
||||||
return param_str, ret
|
return param_str, ret
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user