summaryrefslogtreecommitdiff
path: root/logilab/common/deprecation.py
diff options
context:
space:
mode:
Diffstat (limited to 'logilab/common/deprecation.py')
-rw-r--r--logilab/common/deprecation.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/logilab/common/deprecation.py b/logilab/common/deprecation.py
index cdf538c..636b498 100644
--- a/logilab/common/deprecation.py
+++ b/logilab/common/deprecation.py
@@ -283,11 +283,28 @@ class class_deprecated(type):
return type.__call__(cls, *args, **kwargs)
-def moved(modpath, objname):
- return _defaultdeprecator.moved(None, modpath, objname)
+def moved(modpath, objname, version=None, stacklevel=2):
+ """use to tell that a callable has been moved to a new module.
+ It returns a callable wrapper, so that when its called a warning is printed
+ telling where the object can be found, import is done (and not before) and
+ the actual object is called.
+
+ NOTE: the usage is somewhat limited on classes since it will fail if the
+ wrapper is use in a class ancestors list, use the `class_moved` function
+ instead (which has no lazy import feature though).
+ """
+ message = "object %s has been moved to module %s" % (objname, modpath)
+
+ def callnew(*args, **kwargs):
+ from logilab.common.modutils import load_module_from_name
+
+ send_warning(message, version=version, stacklevel=stacklevel + 1)
+
+ m = load_module_from_name(modpath)
+ return getattr(m, objname)(*args, **kwargs)
-moved.__doc__ = _defaultdeprecator.moved.__doc__
+ return callnew
def attribute_renamed(old_name, new_name):