diff options
author | Josh Wilson <person142@users.noreply.github.com> | 2019-01-22 20:25:46 -0800 |
---|---|---|
committer | Brigitta Sipőcz <bsipocz@gmail.com> | 2022-09-21 12:17:31 -0700 |
commit | 052db426f5139936e578f9ccba31a2d6f98bc2fd (patch) | |
tree | db73f3b05b1ab647085ee0d37642d931e105e430 /numpy/lib/utils.py | |
parent | 7e9f225ce23fd6df6893020f54b1b5daf883f9b9 (diff) | |
download | numpy-052db426f5139936e578f9ccba31a2d6f98bc2fd.tar.gz |
MAINT: use `functools.wraps` in `np.deprecate`
Diffstat (limited to 'numpy/lib/utils.py')
-rw-r--r-- | numpy/lib/utils.py | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index c0c55ea8e..497827e75 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -4,6 +4,7 @@ import textwrap import types import re import warnings +import functools from numpy.core.numerictypes import issubclass_, issubsctype, issubdtype from numpy.core.overrides import set_module @@ -149,10 +150,7 @@ class _Deprecate: message = self.message if old_name is None: - try: - old_name = func.__name__ - except AttributeError: - old_name = func.__name__ + old_name = func.__name__ if new_name is None: depdoc = "`%s` is deprecated!" % old_name else: @@ -162,8 +160,8 @@ class _Deprecate: if message is not None: depdoc += "\n" + message - def newfunc(*args,**kwds): - """`arrayrange` is deprecated, use `arange` instead!""" + @functools.wraps(func) + def newfunc(*args, **kwds): warnings.warn(depdoc, DeprecationWarning, stacklevel=2) return func(*args, **kwds) @@ -189,16 +187,7 @@ class _Deprecate: depdoc = textwrap.indent(depdoc, ' ' * indent) doc = '\n\n'.join([depdoc, doc]) newfunc.__doc__ = doc - try: - d = func.__dict__ - except AttributeError: - pass - else: - newfunc.__dict__.update(d) - try: - newfunc.__module__ = func.__module__ - except AttributeError: - pass + return newfunc |