summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Peuch <cortex@worlddomination.be>2020-04-22 23:54:47 +0200
committerLaurent Peuch <cortex@worlddomination.be>2020-04-22 23:54:47 +0200
commit290dd7e63ba63159aaba69675c2a23819745eb92 (patch)
treefd7606e8b4cae517ef9236ec8f7cd22fd88cf37c
parentdfcc38f9aa74b8dc579966fb91fbd5c6f3c4eb29 (diff)
downloadlogilab-common-290dd7e63ba63159aaba69675c2a23819745eb92.tar.gz
[deprecation/refactoring] simplify renamed
-rw-r--r--logilab/common/deprecation.py11
-rw-r--r--test/unittest_deprecation.py2
2 files changed, 10 insertions, 3 deletions
diff --git a/logilab/common/deprecation.py b/logilab/common/deprecation.py
index 636b498..4da111b 100644
--- a/logilab/common/deprecation.py
+++ b/logilab/common/deprecation.py
@@ -385,7 +385,7 @@ def argument_renamed(old_name, new_name):
return _wrap
-def renamed(old_name, new_function):
+def renamed(old_name, new_function, version=None):
"""use to tell that a callable has been renamed.
It returns a callable wrapper, so that when its called a warning is printed
@@ -397,7 +397,14 @@ def renamed(old_name, new_function):
old_function()
>>>
"""
- return _defaultdeprecator.renamed(old_name, new_function)
+ @wraps(new_function)
+ def wrapped(*args, **kwargs):
+ send_warning((
+ f"{old_name} has been renamed and is deprecated, uses {new_function.__name__} "
+ f"instead"
+ ), stacklevel=3, version=version)
+ return new_function(*args, **kwargs)
+ return wrapped
def class_renamed(old_name, new_class, message=None):
diff --git a/test/unittest_deprecation.py b/test/unittest_deprecation.py
index 5884235..50fbbb9 100644
--- a/test/unittest_deprecation.py
+++ b/test/unittest_deprecation.py
@@ -126,7 +126,7 @@ class RawInputTC(TestCase):
old_func()
self.assertEqual(self.messages,
- ['old_func has been renamed and is deprecated, uses any_func instead'])
+ ['[logilab.common] old_func has been renamed and is deprecated, uses any_func instead'])
def test_moved(self):
module = 'data.deprecation'