summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorJosh Wilson <person142@users.noreply.github.com>2019-01-19 13:45:26 -0800
committerBrigitta Sipőcz <bsipocz@gmail.com>2022-09-21 12:17:31 -0700
commit7e9f225ce23fd6df6893020f54b1b5daf883f9b9 (patch)
treeec26009094d74e622b3d36e3805c5b3d66138a99 /numpy/lib
parent852f797006aab17d9af9d5f66c9dc2b7afe507d4 (diff)
downloadnumpy-7e9f225ce23fd6df6893020f54b1b5daf883f9b9.tar.gz
MAINT: update function's `__module__` attribute in `deprecate`
Currently the location of the function definition is always reported to be `numpy.lib.utils`; this changes it to be the location of the actual definition when possible.
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/tests/test_utils.py4
-rw-r--r--numpy/lib/utils.py11
2 files changed, 9 insertions, 6 deletions
diff --git a/numpy/lib/tests/test_utils.py b/numpy/lib/tests/test_utils.py
index 72c91836f..6ad4bfe6d 100644
--- a/numpy/lib/tests/test_utils.py
+++ b/numpy/lib/tests/test_utils.py
@@ -115,6 +115,10 @@ def test_deprecate_preserve_whitespace():
assert_('\n Bizarre' in new_func5.__doc__)
+def test_deprecate_module():
+ assert_(old_func.__module__ == __name__)
+
+
def test_safe_eval_nameconstant():
# Test if safe_eval supports Python 3.4 _ast.NameConstant
utils.safe_eval('None')
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py
index 2fcf270c4..c0c55ea8e 100644
--- a/numpy/lib/utils.py
+++ b/numpy/lib/utils.py
@@ -122,11 +122,6 @@ def get_include():
return d
-def _set_function_name(func, name):
- func.__name__ = name
- return func
-
-
class _Deprecate:
"""
Decorator class to deprecate old functions.
@@ -172,7 +167,7 @@ class _Deprecate:
warnings.warn(depdoc, DeprecationWarning, stacklevel=2)
return func(*args, **kwds)
- newfunc = _set_function_name(newfunc, old_name)
+ newfunc.__name__ = old_name
doc = func.__doc__
if doc is None:
doc = depdoc
@@ -200,6 +195,10 @@ class _Deprecate:
pass
else:
newfunc.__dict__.update(d)
+ try:
+ newfunc.__module__ = func.__module__
+ except AttributeError:
+ pass
return newfunc