Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5035755

Browse files
authored
Merge pull request #498 from python/feature/entry-points-disallow-dist-match
Disallow passing of 'dist' to EntryPoints.select.
2 parents 6d9b766 + 875003a commit 5035755

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

importlib_metadata/__init__.py

+17
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,26 @@ def matches(self, **params):
227227
>>> ep.matches(attr='bong')
228228
True
229229
"""
230+
self._disallow_dist(params)
230231
attrs = (getattr(self, param) for param in params)
231232
return all(map(operator.eq, params.values(), attrs))
232233

234+
@staticmethod
235+
def _disallow_dist(params):
236+
"""
237+
Querying by dist is not allowed (dist objects are not comparable).
238+
>>> EntryPoint(name='fan', value='fav', group='fag').matches(dist='foo')
239+
Traceback (most recent call last):
240+
...
241+
ValueError: "dist" is not suitable for matching...
242+
"""
243+
if "dist" in params:
244+
raise ValueError(
245+
'"dist" is not suitable for matching. '
246+
"Instead, use Distribution.entry_points.select() on a "
247+
"located distribution."
248+
)
249+
233250
def _key(self):
234251
return self.name, self.value, self.group
235252

newsfragments/+29a322e3.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Disallow passing of 'dist' to EntryPoints.select.

0 commit comments

Comments
 (0)