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.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/logilab/common/deprecation.py b/logilab/common/deprecation.py
index 577aee7..4aaeba3 100644
--- a/logilab/common/deprecation.py
+++ b/logilab/common/deprecation.py
@@ -268,6 +268,33 @@ def argument_renamed(old_name, new_name):
return _wrap
+def argument_removed(old_argument_name):
+ """
+ callable decorator to allow getting backward compatibility for renamed keyword arguments.
+
+ >>> @argument_removed("old")
+ ... def some_function(new):
+ ... return new
+ >>> some_function(old=42)
+ sample.py:15: DeprecationWarning: argument old of callable some_function has been renamed and is deprecated, use keyword argument new instead
+ some_function(old=42)
+ 42
+ """
+ def _wrap(func):
+ @wraps(func)
+ def check_kwargs(*args, **kwargs):
+ if old_argument_name in kwargs:
+ warn(f"argument {old_argument_name} of callable {func.__name__} has been removed and is "
+ f"deprecated", stacklevel=2)
+ del kwargs[old_argument_name]
+
+ return func(*args, **kwargs)
+
+ return check_kwargs
+
+ return _wrap
+
+
def renamed(old_name, new_function):
"""use to tell that a callable has been renamed.