summaryrefslogtreecommitdiff
path: root/logilab/common
diff options
context:
space:
mode:
authorLaurent Peuch <cortex@worlddomination.be>2020-05-07 22:30:19 +0200
committerLaurent Peuch <cortex@worlddomination.be>2020-05-07 22:30:19 +0200
commit6528cabe3576bd4002199561da046324f3f44d38 (patch)
treed6a9f349a701df5690a178eee81ffae0bb3f3d48 /logilab/common
parent30d47f2bd6c3fb00108a7f2faebade1a30836fef (diff)
downloadlogilab-common-6528cabe3576bd4002199561da046324f3f44d38.tar.gz
[deprecation] simplify class_deprecated code
I don't know why it has been choosen to move to a metaclass but it actually brings more problems and a more complex code that it brings benefits.
Diffstat (limited to 'logilab/common')
-rw-r--r--logilab/common/deprecation.py52
1 files changed, 17 insertions, 35 deletions
diff --git a/logilab/common/deprecation.py b/logilab/common/deprecation.py
index a6f448f..5dc23f7 100644
--- a/logilab/common/deprecation.py
+++ b/logilab/common/deprecation.py
@@ -177,41 +177,23 @@ def callable_deprecated(reason=None, version=None, stacklevel=2):
deprecated = callable_renamed(old_name="deprecated", new_function=callable_deprecated)
-def class_deprecated(old_name, parents, class_dict):
- try:
- return _class_deprecated(old_name, parents, clsdict)
- except (NameError, TypeError):
- # in case of conflicting metaclass situation
- class DeprecatedClass(*parents):
- def __init__(self, *args, **kwargs):
- msg = class_dict.get("__deprecation_warning__", f"{old_name} is deprecated")
- send_warning(
- msg,
- stacklevel=class_dict.get("__deprecation_warning_stacklevel__", 3),
- version=class_dict.get("__deprecation_warning_version__", None),
- module_name=class_dict.get(
- "__deprecation_warning_module_name__", _get_module_name(1)
- ),
- )
- super(DeprecatedClass, self).__init__(*args, **kwargs)
-
- return DeprecatedClass
-
-
-class _class_deprecated(type):
- """metaclass to print a warning on instantiation of a deprecated class"""
-
- def __call__(cls, *args, **kwargs):
- msg = getattr(cls, "__deprecation_warning__", "%(cls)s is deprecated") % {
- "cls": cls.__name__
- }
- send_warning(
- msg,
- stacklevel=getattr(cls, "__deprecation_warning_stacklevel__", 3),
- version=getattr(cls, "__deprecation_warning_version__", None),
- module_name=getattr(cls, "__deprecation_warning_module_name__", cls.__module__),
- )
- return type.__call__(cls, *args, **kwargs)
+def class_deprecated(old_name, parent, class_dict):
+ class DeprecatedClass(*parent):
+ def __init__(self, *args, **kwargs):
+ msg = class_dict.get("__deprecation_warning__", f"{old_name} is deprecated")
+ send_warning(
+ msg,
+ stacklevel=class_dict.get("__deprecation_warning_stacklevel__", 3),
+ version=class_dict.get("__deprecation_warning_version__", None),
+ module_name=class_dict.get(
+ "__deprecation_warning_module_name__", _get_module_name(1)
+ ),
+ )
+ super(DeprecatedClass, self).__init__(*args, **kwargs)
+
+ DeprecatedClass.__name__ = old_name
+
+ return DeprecatedClass
def attribute_renamed(old_name, new_name, version=None):