Ignore warnings for numpydocs

This commit is contained in:
Dave Halter
2019-06-10 21:41:15 +02:00
parent 1b0677ec55
commit c1047bef4f

View File

@@ -16,6 +16,7 @@ annotations.
""" """
import re import re
import warnings
from textwrap import dedent from textwrap import dedent
from parso import parse, ParserSyntaxError from parso import parse, ParserSyntaxError
@@ -60,12 +61,14 @@ def _get_numpy_doc_string_cls():
def _search_param_in_numpydocstr(docstr, param_str): 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: with warnings.catch_warnings():
# This is a non-public API. If it ever changes we should be warnings.simplefilter("ignore")
# prepared and return gracefully. try:
params = _get_numpy_doc_string_cls()(docstr)._parsed_data['Parameters'] # This is a non-public API. If it ever changes we should be
except Exception: # prepared and return gracefully.
return [] params = _get_numpy_doc_string_cls()(docstr)._parsed_data['Parameters']
except Exception:
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:
m = re.match(r'([^,]+(,[^,]+)*?)(,[ ]*optional)?$', p_type) m = re.match(r'([^,]+(,[^,]+)*?)(,[ ]*optional)?$', p_type)
@@ -79,10 +82,12 @@ 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.
""" """
try: with warnings.catch_warnings():
doc = _get_numpy_doc_string_cls()(docstr) warnings.simplefilter("ignore")
except Exception: try:
return doc = _get_numpy_doc_string_cls()(docstr)
except Exception:
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.