Skip to content

Commit

Permalink
Disallow passing of 'dist' to EntryPoints.select.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Aug 1, 2024
1 parent 5ddd122 commit 875003a
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 875003a

Please sign in to comment.