1
0
forked from VimPlug/jedi

Don't import numpydoc in the beginning

There were issues in combination with importing it with subprocesses
This commit is contained in:
Dave Halter
2017-12-18 01:34:19 +01:00
parent 8b3ee75654
commit f5c7e3bb06

View File

@@ -42,49 +42,59 @@ DOCSTRING_RETURN_PATTERNS = [
REST_ROLE_PATTERN = re.compile(r':[^`]+:`([^`]+)`') REST_ROLE_PATTERN = re.compile(r':[^`]+:`([^`]+)`')
try: _numpy_doc_string_cache = None
from numpydoc.docscrape import NumpyDocString
except ImportError:
def _search_param_in_numpydocstr(docstr, param_str):
return []
def _search_return_in_numpydocstr(docstr):
return []
else:
def _search_param_in_numpydocstr(docstr, param_str):
"""Search `docstr` (in numpydoc format) for type(-s) of `param_str`."""
try:
# This is a non-public API. If it ever changes we should be
# prepared and return gracefully.
params = NumpyDocString(docstr)._parsed_data['Parameters']
except (KeyError, AttributeError):
return []
for p_name, p_type, p_descr in params:
if p_name == param_str:
m = re.match('([^,]+(,[^,]+)*?)(,[ ]*optional)?$', p_type)
if m:
p_type = m.group(1)
return list(_expand_typestr(p_type))
return []
def _search_return_in_numpydocstr(docstr): def _get_numpy_doc_string_cls():
""" global _numpy_doc_string_cache
Search `docstr` (in numpydoc format) for type(-s) of function returns. try:
""" from numpydoc.docscrape import NumpyDocString
doc = NumpyDocString(docstr) _numpy_doc_string_cache = NumpyDocString
try: except ImportError as e:
# This is a non-public API. If it ever changes we should be _numpy_doc_string_cache = e
# prepared and return gracefully. if isinstance(_numpy_doc_string_cache, ImportError):
returns = doc._parsed_data['Returns'] raise _numpy_doc_string_cache
returns += doc._parsed_data['Yields'] return _numpy_doc_string_cache
except (KeyError, AttributeError):
raise StopIteration
for r_name, r_type, r_descr in returns: def _search_param_in_numpydocstr(docstr, param_str):
#Return names are optional and if so the type is in the name """Search `docstr` (in numpydoc format) for type(-s) of `param_str`."""
if not r_type: try:
r_type = r_name # This is a non-public API. If it ever changes we should be
for type_ in _expand_typestr(r_type): # prepared and return gracefully.
yield type_ params = _get_numpy_doc_string_cls()(docstr)._parsed_data['Parameters']
except (KeyError, AttributeError, ImportError):
return []
for p_name, p_type, p_descr in params:
if p_name == param_str:
m = re.match('([^,]+(,[^,]+)*?)(,[ ]*optional)?$', p_type)
if m:
p_type = m.group(1)
return list(_expand_typestr(p_type))
return []
def _search_return_in_numpydocstr(docstr):
"""
Search `docstr` (in numpydoc format) for type(-s) of function returns.
"""
try:
doc = _get_numpy_doc_string_cls()(docstr)
except ImportError:
return
try:
# This is a non-public API. If it ever changes we should be
# prepared and return gracefully.
returns = doc._parsed_data['Returns']
returns += doc._parsed_data['Yields']
except (KeyError, AttributeError):
return
for r_name, r_type, r_descr in returns:
# Return names are optional and if so the type is in the name
if not r_type:
r_type = r_name
for type_ in _expand_typestr(r_type):
yield type_
def _expand_typestr(type_str): def _expand_typestr(type_str):