Skip to content

Commit

Permalink
Use @deprecated for __setitem__ and __delitem__ of Registry.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-six authored May 16, 2022
1 parent 0394b26 commit 7334ecd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
14 changes: 2 additions & 12 deletions markdown/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,10 @@ def _sort(self):

# 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
Expand All @@ -410,16 +405,11 @@ def __setitem__(self, key, value):
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))

Expand Down
2 changes: 1 addition & 1 deletion tests/test_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def testRegistryDelItem(self):
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):
Expand Down

0 comments on commit 7334ecd

Please sign in to comment.