importlib_metadata icon indicating copy to clipboard operation
importlib_metadata copied to clipboard

Consider adding back a warning instead of KeyError

Open hmaarrfk opened this issue 1 year ago • 0 comments

I'm not sure where best to post this, but I hit the KeyError in the wild on some projects that are quite good at keeping up with python best practices.

I think it is because the previous warning was not something that would be easily triggered by the CIs:

# Do not remove prior to 2024-01-01 or Python 3.14
_warn = functools.partial(
    warnings.warn,
    "Implicit None on return values is deprecated and will raise KeyErrors.",
    DeprecationWarning,
    stacklevel=pypy_partial(2),
)

https://github.com/python/importlib_metadata/commit/a970a491b56a3bf529821ce21867af4573cf2e0d

Ultimately, I believe this warning gets triggered when somebody uses importlib_metadata to crawl through the user's installed directories. This means that it is prone to producing more errors on the users installation and not the "perfectly crafted CI environments". Whats worse (I think) is that this might catch some namespace packages that are left-over from bad installation procedures.

If I would have caught this warning (as an advanced user) I would have reported it to the impacted project https://github.com/cupy/cupy/issues/8440 however, since as a user I would have very little chance of seeing this since it is hidden behind a DeprecationWarning, I was unable to warn the project downstream to importlib_metadata

Would it be acceptable to add back the warning but to elevate it to a UserWarning?

hmaarrfk avatar Jul 25 '24 11:07 hmaarrfk