From 052db426f5139936e578f9ccba31a2d6f98bc2fd Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Tue, 22 Jan 2019 20:25:46 -0800 Subject: MAINT: use `functools.wraps` in `np.deprecate` --- numpy/lib/utils.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'numpy/lib/utils.py') 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 -- cgit v1.2.1