From da334a857b78de3749dc69a81b074d86c6bbea2b Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Thu, 30 Apr 2020 14:02:07 +0200 Subject: [deprecation/abbreviation] rename modpath/objname function arguments to module_name/object_name --- logilab/common/deprecation.py | 50 ++++++++++++++++++++++--------------------- 1 file 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. -- cgit v1.2.1