Closed
Description
Since #449 trying to use missing extras raises AssertionErrors. I believe that invalid inputs should never raise AssertionErrors (neither should asserts be used to validate user input).
Observe on Python 3.12 (before this change):
>>> ep = importlib.metadata.EntryPoint(name='foo', value='invalid-identifier:foo', group='foo')
>>> ep.extras
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python3.12/importlib/metadata/__init__.py", line 222, in extras
return re.findall(r'\w+', match.group('extras') or '')
^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'group'
Now this exception message is bogus but at least this is an AttributeError (hence code reading this might assume the .extras attribute is missing).
However, on Python 3.13:
>>> ep = importlib.metadata.EntryPoint(name='foo', value='invalid-identifier:foo', group='foo')
>>> ep.extras
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
ep.extras
File "/usr/lib64/python3.13/importlib/metadata/__init__.py", line 198, in extras
assert match is not None
^^^^^^^^^^^^^^^^^
AssertionError
Existing code (e.g. setuptools) assumes AttributeError in this case:
I believe both behaviors are wrong, but the new one is "more wrong".
May I suggest that either .extras
or .__init__
raises a specific exception when this happens?
Metadata
Metadata
Assignees
Labels
No labels