summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utils.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/utils.py b/utils.py
index 8031fdf75..edde2d168 100644
--- a/utils.py
+++ b/utils.py
@@ -7,7 +7,8 @@ from numpy.core.multiarray import dtype as _dtype
from numpy.core import product, ndarray
__all__ = ['issubclass_', 'get_numpy_include', 'issubsctype',
- 'issubdtype', 'deprecate', 'get_numarray_include',
+ 'issubdtype', 'deprecate', 'deprecate_with_doc',
+ 'get_numarray_include',
'get_include', 'info', 'source', 'who',
'byte_bounds', 'may_share_memory']
@@ -82,15 +83,22 @@ else:
func.__name__ = name
return func
-def deprecate(func, oldname, newname):
+def deprecate(func, oldname=None, newname=None):
import warnings
+ if oldname is None:
+ oldname = func.func_name
+ if newname is None:
+ str1 = "%s is deprecated" % (oldname,)
+ depdoc = "%s is DEPRECATED!" % (oldname,)
+ else:
+ str1 = "%s is deprecated, use %s" % (oldname, newname),
+ depdoc = '%s is DEPRECATED! -- use %s instead' % (oldname, newname,)
+
def newfunc(*args,**kwds):
- warnings.warn("%s is deprecated, use %s" % (oldname, newname),
- DeprecationWarning)
+ warnings.warn(str1, DeprecationWarning)
return func(*args, **kwds)
newfunc = _set_function_name(newfunc, oldname)
doc = func.__doc__
- depdoc = '%s is DEPRECATED: use %s instead' % (oldname, newname,)
if doc is None:
doc = depdoc
else:
@@ -104,6 +112,13 @@ def deprecate(func, oldname, newname):
newfunc.__dict__.update(d)
return newfunc
+def deprecate_with_doc(somestr):
+ def _decorator(func):
+ newfunc = deprecate(func)
+ newfunc.__doc__ += "\n" + somestr
+ return newfunc
+ return _decorator
+
get_numpy_include = deprecate(get_include, 'get_numpy_include', 'get_include')