Skip to content

Commit eae6a75

Browse files
committed
Raise a ValueError if no match.
Closes #488
1 parent 55c6070 commit eae6a75

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

importlib_metadata/__init__.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,22 @@ class EntryPoint:
155155
'attr'
156156
>>> ep.extras
157157
['extra1', 'extra2']
158+
159+
If the value package or module are not valid identifiers, a
160+
ValueError is raised on access.
161+
162+
>>> EntryPoint(name=None, group=None, value='invalid-name').module
163+
Traceback (most recent call last):
164+
...
165+
ValueError: ('Invalid object reference...invalid-name...
166+
>>> EntryPoint(name=None, group=None, value='invalid-name').attr
167+
Traceback (most recent call last):
168+
...
169+
ValueError: ('Invalid object reference...invalid-name...
170+
>>> EntryPoint(name=None, group=None, value='invalid-name').extras
171+
Traceback (most recent call last):
172+
...
173+
ValueError: ('Invalid object reference...invalid-name...
158174
"""
159175

160176
pattern = re.compile(
@@ -211,7 +227,13 @@ def extras(self) -> list[str]:
211227
@property
212228
def _match(self) -> _EntryPointMatch:
213229
match = self.pattern.match(self.value)
214-
assert match is not None
230+
if not match:
231+
raise ValueError(
232+
'Invalid object reference. '
233+
'See https://packaging.python.org'
234+
'/en/latest/specifications/entry-points/#data-model',
235+
self.value,
236+
)
215237
return _EntryPointMatch(**match.groupdict())
216238

217239
def _for(self, dist):

0 commit comments

Comments
 (0)