Skip to content

Commit ecb363c

Browse files
committed
Simply wrap .matches instead of replacing EntryPoint.
1 parent 9a6641b commit ecb363c

File tree

2 files changed

+5
-19
lines changed

2 files changed

+5
-19
lines changed

importlib_metadata/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,7 @@ def select(self, **params):
382382
Select entry points from self that match the
383383
given parameters (typically group and/or name).
384384
"""
385-
candidates = (_py39compat.ep_matches(ep, **params) for ep in self)
386-
return EntryPoints(ep for ep, predicate in candidates if predicate)
385+
return EntryPoints(ep for ep in self if _py39compat.ep_matches(ep, **params))
387386

388387
@property
389388
def names(self):

importlib_metadata/_py39compat.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Compatibility layer with Python 3.8/3.9
33
"""
4-
from typing import TYPE_CHECKING, Any, Optional, Tuple
4+
from typing import TYPE_CHECKING, Any, Optional
55

66
if TYPE_CHECKING: # pragma: no cover
77
# Prevent circular imports on runtime.
@@ -22,27 +22,14 @@ def normalized_name(dist: Distribution) -> Optional[str]:
2222
return Prepared.normalize(getattr(dist, "name", None) or dist.metadata['Name'])
2323

2424

25-
def ep_matches(ep: EntryPoint, **params) -> Tuple[EntryPoint, bool]:
25+
def ep_matches(ep: EntryPoint, **params) -> bool:
2626
"""
2727
Workaround for ``EntryPoint`` objects without the ``matches`` method.
28-
For the sake of convenience, a tuple is returned containing not only the
29-
boolean value corresponding to the predicate evalutation, but also a compatible
30-
``EntryPoint`` object that can be safely used at a later stage.
31-
32-
For example, the following sequences of expressions should be compatible:
33-
34-
# Sequence 1: using the compatibility layer
35-
candidates = (_py39compat.ep_matches(ep, **params) for ep in entry_points)
36-
[ep for ep, predicate in candidates if predicate]
37-
38-
# Sequence 2: using Python 3.9+
39-
[ep for ep in entry_points if ep.matches(**params)]
4028
"""
4129
try:
42-
return ep, ep.matches(**params)
30+
return ep.matches(**params)
4331
except AttributeError:
4432
from . import EntryPoint # -> delay to prevent circular imports.
4533

4634
# Reconstruct the EntryPoint object to make sure it is compatible.
47-
_ep = EntryPoint(ep.name, ep.value, ep.group)
48-
return _ep, _ep.matches(**params)
35+
return EntryPoint(ep.name, ep.value, ep.group).matches(**params)

0 commit comments

Comments
 (0)