summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorL <leven.cn@gmail.com>2022-05-17 02:23:39 +0800
committerGitHub <noreply@github.com>2022-05-16 14:23:39 -0400
commit7334ecd4c747f9a36351a5073b55c2a606917ef9 (patch)
tree8db483032514a2c676fe99509c8467817d6e7634
parent0394b26c61014feea4d5be4f543f2caa7f058b0b (diff)
downloadpython-markdown-7334ecd4c747f9a36351a5073b55c2a606917ef9.tar.gz
Use `@deprecated` for __setitem__ and __delitem__ of Registry.
-rw-r--r--markdown/util.py14
-rw-r--r--tests/test_apis.py2
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):