python / importlib_metadata

Library to access metadata for Python packages
https://importlib-metadata.readthedocs.io
Apache License 2.0
126 stars 81 forks source link

Provide a helper for "is distribution present" #477

Closed jaraco closed 6 months ago

jaraco commented 10 months ago

In https://github.com/python/mypy/issues/16400#issuecomment-1828013480, I discovered that there's no convenient function to determine "is a distribution present". The distribution function does return the distribution or raise an Exception if not present, but in some cases, it may be preferable to trap the exception and translate it into a boolean.

jaraco commented 10 months ago

On second thought - maybe the Pythonic way to handle trapping an exception is to just use try/except. I'll consider that for the aforementioned issue.

jaraco commented 6 months ago

Since no one has commented on this issue, I'm going to close it for now as "won't fix", but I'm happy to revisit if there are additional cases that could benefit from this behavior. Maybe we add a Distribution.exists() that wraps the try/except.