Open hroncok opened 6 months ago
Thanks for the report. Without looking at the code, I agree the API should provide a documented expectation for erroneous inputs, especially if callers are relying on that interface to perform validation (as seems to be the case).
I suspect what was going on here is the code is basically expecting valid input and providing some best-effort checks to validate the input, but not expecting the exceptional case to be encountered except under broken callers.
Since https://github.com/python/importlib_metadata/pull/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):
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:
Existing code (e.g. setuptools) assumes AttributeError in this case:
See https://github.com/pypa/setuptools/blob/544b332bd78d8d274597923e89b9bd7839f8a0f4/setuptools/_entry_points.py#L18-L25
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?