Commit 25bae5f3 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

[fix] metaclass conflict for class_deprecated

Actually the old compatibility code actually prevented this bug so back it up.
parent 926cb8c5eb20
......@@ -177,7 +177,28 @@ def callable_deprecated(reason=None, version=None, stacklevel=2):
deprecated = callable_renamed(old_name="deprecated", new_function=callable_deprecated)
class class_deprecated(type):
def class_deprecated(old_name, parents, class_dict):
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")
stacklevel=class_dict.get("__deprecation_warning_stacklevel__", 3),
version=class_dict.get("__deprecation_warning_version__", None),
"__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):
......@@ -63,6 +63,17 @@ class RawInputTC(TestCase):
self.messages, ["[test_deprecation] OldClass is deprecated, use AnyClass instead"]
def test_class_renamed_conflict_metaclass(self):
class SomeMetaClass(type):
class AnyClass(metaclass=SomeMetaClass):
# make sure the "metaclass conflict: the metaclass of a derived class # must be a
# (non-strict) subclass of the metaclasses of all its bases" exception won't be raised
deprecation.class_renamed("OldClass", AnyClass)
def test_class_moved(self):
class AnyClass(object):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment