summaryrefslogtreecommitdiff
path: root/utils.py
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2007-12-15 22:27:46 +0000
committerTravis Oliphant <oliphant@enthought.com>2007-12-15 22:27:46 +0000
commit94e351cbda3fb151af4ae18d6ebfc9b409e27022 (patch)
treebb9603cb3baef781ac45aa8c5d6fd2c94a449665 /utils.py
parentb539432af52d63c08435148f987bec05f412f113 (diff)
downloadnumpy-94e351cbda3fb151af4ae18d6ebfc9b409e27022.tar.gz
Add deprecate with doc.
Diffstat (limited to 'utils.py')
-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')