summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Peuch <cortex@worlddomination.be>2020-04-30 14:02:07 +0200
committerLaurent Peuch <cortex@worlddomination.be>2020-04-30 14:02:07 +0200
commitda334a857b78de3749dc69a81b074d86c6bbea2b (patch)
tree6a154eb5f2fb56d7b2268eb51a3c93f34fccc7ac
parent07c6393abb3389787d7e6b98809026da394222ac (diff)
downloadlogilab-common-da334a857b78de3749dc69a81b074d86c6bbea2b.tar.gz
[deprecation/abbreviation] rename modpath/objname function arguments to module_name/object_name
-rw-r--r--logilab/common/deprecation.py50
1 files changed, 26 insertions, 24 deletions
diff --git a/logilab/common/deprecation.py b/logilab/common/deprecation.py
index 88376f8..1c58970 100644
--- a/logilab/common/deprecation.py
+++ b/logilab/common/deprecation.py
@@ -146,30 +146,6 @@ class class_deprecated(type):
return type.__call__(cls, *args, **kwargs)
-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)
-
- return callnew
-
-
def attribute_renamed(old_name, new_name, version=None):
"""
class decorator to allow getting backward compatibility for renamed attributes.
@@ -249,6 +225,32 @@ def argument_renamed(old_name, new_name, version=None):
return _wrap
+@argument_renamed(old_name="modpath", new_name="module_path")
+@argument_renamed(old_name="objname", new_name="object_name")
+def moved(module_name, object_name, 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" % (object_name, module_name)
+
+ 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(module_name)
+ return getattr(m, object_name)(*args, **kwargs)
+
+ return callnew
+
+
def renamed(old_name, new_function, version=None):
"""use to tell that a callable has been renamed.