Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

allow deprecation of subclasses of already deprecated classes

Daniel Graña31dd3dc4a106
diff --git a/scrapy/tests/test_utils_deprecate.py b/scrapy/tests/test_utils_deprecate.py
index 8cc3a26f1..75a53b2bf 100644
--- a/scrapy/tests/test_utils_deprecate.py
+++ b/scrapy/tests/test_utils_deprecate.py
@@ -201,3 +201,27 @@ class WarnWhenSubclassedTest(unittest.TestCase):
Meta1 = type('Meta1', (type,), {})
New = Meta1('New', (), {})
Deprecated = create_deprecated_class('Deprecated', New)
+
+ def test_deprecate_subclass_of_deprecated_class(self):
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter('always')
+ Deprecated = create_deprecated_class('Deprecated', NewName,
+ warn_category=MyWarning)
+ AlsoDeprecated = create_deprecated_class('AlsoDeprecated', Deprecated,
+ new_class_path='foo.Bar',
+ warn_category=MyWarning)
+
+ w = self._mywarnings(w)
+ self.assertEqual(len(w), 0, str(map(str, w)))
+
+ with warnings.catch_warnings(record=True) as w:
+ AlsoDeprecated()
+ class UserClass(AlsoDeprecated):
+ pass
+
+ w = self._mywarnings(w)
+ self.assertEqual(len(w), 2)
+ self.assertIn('AlsoDeprecated', str(w[0].message))
+ self.assertIn('foo.Bar', str(w[0].message))
+ self.assertIn('AlsoDeprecated', str(w[1].message))
+ self.assertIn('foo.Bar', str(w[1].message))
diff --git a/scrapy/utils/deprecate.py b/scrapy/utils/deprecate.py
index 47d97e9cb..edaecc3d3 100644
--- a/scrapy/utils/deprecate.py
+++ b/scrapy/utils/deprecate.py
@@ -87,8 +87,7 @@ def create_deprecated_class(name, new_class, clsdict=None,
return any(c in candidates for c in mro)
def __call__(cls, *args, **kwargs):
- meta = cls.__class__
- old = meta.deprecated_class
+ old = DeprecatedClass.deprecated_class
if cls is old:
msg = instance_warn_message.format(cls=_clspath(cls, old_class_path),
new=_clspath(new_class, new_class_path))