summaryrefslogtreecommitdiff
path: root/numpy/core/function_base.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2019-07-06 16:08:17 -0700
committerMatti Picus <matti.picus@gmail.com>2019-07-06 16:08:17 -0700
commit7ac7fa9a4621f7392f534b20f0cdd64967e9c7eb (patch)
tree7c277762efd84f59d11e07720ad2995d361ff308 /numpy/core/function_base.py
parent57b16ed568581c33d0a6b6d3d4254dce3b67b321 (diff)
downloadnumpy-7ac7fa9a4621f7392f534b20f0cdd64967e9c7eb.tar.gz
MAINT/BUG/DOC: Fix errors in _add_newdocs (#13876)
* BUG: Remove items from `multiarray.__all__` which do not exist on python 3 Avoid using `_add_newdocs` if these functions do not exist. Leaving the version-checking here so that we can backport to 1.16 * BUG: Add missing `np.core.multiarray._get_ndarray_c_version` function This must have been lost in the multiarray / umath merge. Found by noticing that `add_newdocs` was being called on an object that does not exist. * DOC: Remove documentation for property that does not exist `ndarray._as_parameter_` is not a real thing * DOC: Remove docstrings which are duplicated from `numpy/core/multiarray.py` * BUG: Don't silence errors in add_newdoc caused by bad arguments This caught us trying to document members that don't exist.
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())