diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2019-06-30 12:19:06 -0700 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2019-06-30 12:42:00 -0700 |
commit | b592e8f34ef750579b752c590338b3f7cbe92939 (patch) | |
tree | 600829ed94c25dd913fb22acd27340170d494f72 /numpy/core/function_base.py | |
parent | 598fcb41600b809da59456d5e4a7ea549fcae139 (diff) | |
download | numpy-b592e8f34ef750579b752c590338b3f7cbe92939.tar.gz |
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.py | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/numpy/core/function_base.py b/numpy/core/function_base.py index b68fd4068..a7700bb73 100644 --- a/numpy/core/function_base.py +++ b/numpy/core/function_base.py @@ -428,6 +428,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. @@ -442,21 +449,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()) |