Skip to content

Commit

Permalink
Re-use _dispatch in place of _make_predicate.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Dec 9, 2023
1 parent 7ccf80f commit 1dd12d6
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions jaraco/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,21 +1057,6 @@ def random(self):
return self[selector]


@functools.singledispatch
def _make_predicate(param: Union[str, callable]) -> callable:
return param


@_make_predicate.register
def _(param: str):
return _make_predicate(re.compile(param))


@_make_predicate.register
def _(param: re.Pattern):
return param.match


def remove_matching(
orig: collections.abc.MutableMapping[Any:Any], predicate: Union[str, callable]
):
Expand All @@ -1086,7 +1071,7 @@ def remove_matching(
>>> d
{'e': 5, 'f': 6, 'g': 7}
"""
remove_keys(orig, filter(_make_predicate(predicate), orig))
remove_keys(orig, filter(_dispatch(predicate), orig))


def remove_keys(target: collections.abc.MutableMapping, keys):
Expand Down

0 comments on commit 1dd12d6

Please sign in to comment.