From 7334ecd4c747f9a36351a5073b55c2a606917ef9 Mon Sep 17 00:00:00 2001 From: L Date: Tue, 17 May 2022 02:23:39 +0800 Subject: Use `@deprecated` for __setitem__ and __delitem__ of Registry. --- markdown/util.py | 14 ++------------ tests/test_apis.py | 2 +- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/markdown/util.py b/markdown/util.py index c31f6e2..4c690c0 100644 --- a/markdown/util.py +++ b/markdown/util.py @@ -387,15 +387,10 @@ class Registry: # Deprecated Methods which provide a smooth transition from OrderedDict + @deprecated('Use the `register` method instead.') def __setitem__(self, key, value): """ Register item with priority 5 less than lowest existing priority. """ if isinstance(key, str): - warnings.warn( - 'Using setitem to register a processor or pattern is deprecated. ' - 'Use the `register` method instead.', - DeprecationWarning, - stacklevel=2, - ) if key in self: # Key already exists, replace without altering priority self._data[key] = value @@ -410,16 +405,11 @@ class Registry: else: raise TypeError + @deprecated('Use the `deregister` method instead.') def __delitem__(self, key): """ Deregister an item by name. """ if key in self: self.deregister(key) - warnings.warn( - 'Using del to remove a processor or pattern is deprecated. ' - 'Use the `deregister` method instead.', - DeprecationWarning, - stacklevel=2, - ) else: raise KeyError('Cannot delete key {}, not registered.'.format(key)) diff --git a/tests/test_apis.py b/tests/test_apis.py index c977e6b..7a3c735 100644 --- a/tests/test_apis.py +++ b/tests/test_apis.py @@ -358,7 +358,7 @@ class RegistryTests(unittest.TestCase): self.assertEqual(list(r), []) # Check the warnings - self.assertEqual(len(w), 3) + self.assertEqual(len(w), 4) self.assertTrue(all(issubclass(x.category, DeprecationWarning) for x in w)) def testRegistrySlice(self): -- cgit v1.2.1