Skip to content

Commit

Permalink
Merge pull request #498 from python/feature/entry-points-disallow-dis…
Browse files Browse the repository at this point in the history
…t-match

Disallow passing of 'dist' to EntryPoints.select.
  • Loading branch information
jaraco authored Aug 19, 2024
2 parents 6d9b766 + 875003a commit 5035755
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,26 @@ def matches(self, **params):
>>> ep.matches(attr='bong')
True
"""
self._disallow_dist(params)
attrs = (getattr(self, param) for param in params)
return all(map(operator.eq, params.values(), attrs))

@staticmethod
def _disallow_dist(params):
"""
Querying by dist is not allowed (dist objects are not comparable).
>>> EntryPoint(name='fan', value='fav', group='fag').matches(dist='foo')
Traceback (most recent call last):
...
ValueError: "dist" is not suitable for matching...
"""
if "dist" in params:
raise ValueError(
'"dist" is not suitable for matching. '
"Instead, use Distribution.entry_points.select() on a "
"located distribution."
)

def _key(self):
return self.name, self.value, self.group

Expand Down
1 change: 1 addition & 0 deletions newsfragments/+29a322e3.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disallow passing of 'dist' to EntryPoints.select.

0 comments on commit 5035755

Please sign in to comment.