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,22 +42,28 @@ 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 [] def _get_numpy_doc_string_cls():
else: global _numpy_doc_string_cache
def _search_param_in_numpydocstr(docstr, param_str): try:
from numpydoc.docscrape import NumpyDocString
_numpy_doc_string_cache = NumpyDocString
except ImportError as e:
_numpy_doc_string_cache = e
if isinstance(_numpy_doc_string_cache, ImportError):
raise _numpy_doc_string_cache
return _numpy_doc_string_cache
def _search_param_in_numpydocstr(docstr, param_str):
"""Search `docstr` (in numpydoc format) for type(-s) of `param_str`.""" """Search `docstr` (in numpydoc format) for type(-s) of `param_str`."""
try: try:
# This is a non-public API. If it ever changes we should be # This is a non-public API. If it ever changes we should be
# prepared and return gracefully. # prepared and return gracefully.
params = NumpyDocString(docstr)._parsed_data['Parameters'] params = _get_numpy_doc_string_cls()(docstr)._parsed_data['Parameters']
except (KeyError, AttributeError): except (KeyError, AttributeError, ImportError):
return [] return []
for p_name, p_type, p_descr in params: for p_name, p_type, p_descr in params:
if p_name == param_str: if p_name == param_str:
@@ -67,20 +73,24 @@ else:
return list(_expand_typestr(p_type)) return list(_expand_typestr(p_type))
return [] return []
def _search_return_in_numpydocstr(docstr):
def _search_return_in_numpydocstr(docstr):
""" """
Search `docstr` (in numpydoc format) for type(-s) of function returns. Search `docstr` (in numpydoc format) for type(-s) of function returns.
""" """
doc = NumpyDocString(docstr) try:
doc = _get_numpy_doc_string_cls()(docstr)
except ImportError:
return
try: try:
# This is a non-public API. If it ever changes we should be # This is a non-public API. If it ever changes we should be
# prepared and return gracefully. # prepared and return gracefully.
returns = doc._parsed_data['Returns'] returns = doc._parsed_data['Returns']
returns += doc._parsed_data['Yields'] returns += doc._parsed_data['Yields']
except (KeyError, AttributeError): except (KeyError, AttributeError):
raise StopIteration return
for r_name, r_type, r_descr in returns: for r_name, r_type, r_descr in returns:
#Return names are optional and if so the type is in the name # Return names are optional and if so the type is in the name
if not r_type: if not r_type:
r_type = r_name r_type = r_name
for type_ in _expand_typestr(r_type): for type_ in _expand_typestr(r_type):