https://github.com/python/cpython/commit/bcced02604f845b2b71d0a1dd95f95366bd7774d
commit: bcced02604f845b2b71d0a1dd95f95366bd7774d
branch: main
author: Bartosz Sławecki <[email protected]>
committer: jaraco <[email protected]>
date: 2025-10-15T12:49:14-04:00
summary:
gh-140141: Properly break exception chain in
`importlib.metadata.Distribution.from_name` (#140142)
files:
A Misc/NEWS.d/next/Library/2025-10-15-17-23-51.gh-issue-140141.j2mUDB.rst
M Lib/importlib/metadata/__init__.py
diff --git a/Lib/importlib/metadata/__init__.py
b/Lib/importlib/metadata/__init__.py
index 1e2cea4009482a..b010bb8525e5cc 100644
--- a/Lib/importlib/metadata/__init__.py
+++ b/Lib/importlib/metadata/__init__.py
@@ -457,7 +457,7 @@ def from_name(cls, name: str) -> Distribution:
try:
return next(iter(cls._prefer_valid(cls.discover(name=name))))
except StopIteration:
- raise PackageNotFoundError(name)
+ raise PackageNotFoundError(name) from None
@classmethod
def discover(
diff --git
a/Misc/NEWS.d/next/Library/2025-10-15-17-23-51.gh-issue-140141.j2mUDB.rst
b/Misc/NEWS.d/next/Library/2025-10-15-17-23-51.gh-issue-140141.j2mUDB.rst
new file mode 100644
index 00000000000000..2edadbc3e3887c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-10-15-17-23-51.gh-issue-140141.j2mUDB.rst
@@ -0,0 +1,5 @@
+The :py:class:`importlib.metadata.PackageNotFoundError` traceback raised when
+``importlib.metadata.Distribution.from_name`` cannot discover a
+distribution no longer includes a transient :exc:`StopIteration` exception
trace.
+
+Contributed by Bartosz Sławecki in :gh:`140142`.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]