diff options
author | Julian Taylor <jtaylor.debian@googlemail.com> | 2013-11-19 00:25:32 +0100 |
---|---|---|
committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2013-11-19 19:11:27 +0100 |
commit | 66174b8aa5644b11054b72761e89e22fd8a18eae (patch) | |
tree | 00f86588ac54d8233272c18a24c5f2b98d97214c /numpy/lib/function_base.py | |
parent | 74e5c1291c96428ab5dac361edfa94bd2ec51d66 (diff) | |
download | numpy-66174b8aa5644b11054b72761e89e22fd8a18eae.tar.gz |
ENH: improve add_newdocs performance
replace slow exec with a direct __import__.
improves `import numpy` speed by about 10%.
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index a70f74f60..9176d9950 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3110,15 +3110,14 @@ def add_newdoc(place, obj, doc): that the docstrings were changed. """ try: - new = {} - exec('from %s import %s' % (place, obj), new) + new = getattr(__import__(place, globals(), {}, [obj]), obj) if isinstance(doc, str): - add_docstring(new[obj], doc.strip()) + add_docstring(new, doc.strip()) elif isinstance(doc, tuple): - add_docstring(getattr(new[obj], doc[0]), doc[1].strip()) + add_docstring(getattr(new, doc[0]), doc[1].strip()) elif isinstance(doc, list): for val in doc: - add_docstring(getattr(new[obj], val[0]), val[1].strip()) + add_docstring(getattr(new, val[0]), val[1].strip()) except: pass |