summaryrefslogtreecommitdiff
path: root/numpy/core/function_base.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2019-07-08 22:31:07 -0700
committerGitHub <noreply@github.com>2019-07-08 22:31:07 -0700
commitc920f98072226c1604d097bdd40db6c8a5a71f06 (patch)
treea011caa7de7d8a4b0868efc9c198d72f3d143527 /numpy/core/function_base.py
parent3085cb7af7b247c389d7d3023fe09c3e000ab609 (diff)
parentb592e8f34ef750579b752c590338b3f7cbe92939 (diff)
downloadnumpy-c920f98072226c1604d097bdd40db6c8a5a71f06.tar.gz
Merge pull request #13944 from eric-wieser/forbid-_add_newdocs-python
MAINT,BUG,DOC: Fix errors in _add_newdocs
Diffstat (limited to 'numpy/core/function_base.py')
-rw-r--r--numpy/core/function_base.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/numpy/core/function_base.py b/numpy/core/function_base.py
index 296213823..c1067299d 100644
--- a/numpy/core/function_base.py
+++ b/numpy/core/function_base.py
@@ -431,6 +431,13 @@ def geomspace(start, stop, num=50, endpoint=True, dtype=None, axis=0):
#always succeed
+def _add_docstring(obj, doc):
+ try:
+ add_docstring(obj, doc)
+ except Exception:
+ pass
+
+
def add_newdoc(place, obj, doc):
"""
Adds documentation to obj which is in module place.
@@ -445,21 +452,19 @@ def add_newdoc(place, obj, doc):
sequence of length two --> [(method1, docstring1),
(method2, docstring2), ...]
- This routine never raises an error.
+ This routine never raises an error if the docstring can't be written, but
+ will raise an error if the object being documented does not exist.
This routine cannot modify read-only docstrings, as appear
in new-style classes or built-in functions. Because this
routine never raises an error the caller must check manually
that the docstrings were changed.
"""
- try:
- new = getattr(__import__(place, globals(), {}, [obj]), obj)
- if isinstance(doc, str):
- add_docstring(new, doc.strip())
- elif isinstance(doc, tuple):
- add_docstring(getattr(new, doc[0]), doc[1].strip())
- elif isinstance(doc, list):
- for val in doc:
- add_docstring(getattr(new, val[0]), val[1].strip())
- except Exception:
- pass
+ new = getattr(__import__(place, globals(), {}, [obj]), obj)
+ if isinstance(doc, str):
+ _add_docstring(new, doc.strip())
+ elif isinstance(doc, tuple):
+ _add_docstring(getattr(new, doc[0]), doc[1].strip())
+ elif isinstance(doc, list):
+ for val in doc:
+ _add_docstring(getattr(new, val[0]), val[1].strip())