From dbe114cbdc49ff42026974e48ca7178a091e7530 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 13 Mar 2022 10:57:22 -0400 Subject: [PATCH] Add docstring with tests for EntryPoint.matches. Ref #373. --- importlib_metadata/__init__.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index 25f34b8d..5ac8be23 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -235,6 +235,25 @@ def __iter__(self): return iter((self.name, self)) def matches(self, **params): + """ + EntryPoint matches the given parameters. + + >>> ep = EntryPoint(group='foo', name='bar', value='bing:bong [extra1, extra2]') + >>> ep.matches(group='foo') + True + >>> ep.matches(name='bar', value='bing:bong [extra1, extra2]') + True + >>> ep.matches(group='foo', name='other') + False + >>> ep.matches() + True + >>> ep.matches(extras=['extra1', 'extra2']) + True + >>> ep.matches(module='bing') + True + >>> ep.matches(attr='bong') + True + """ attrs = (getattr(self, param) for param in params) return all(map(operator.eq, params.values(), attrs))