Skip to content

Commit bcced02

Browse files
authored
gh-140141: Properly break exception chain in importlib.metadata.Distribution.from_name (#140142)
1 parent f673f0e commit bcced02

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Lib/importlib/metadata/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def from_name(cls, name: str) -> Distribution:
457457
try:
458458
return next(iter(cls._prefer_valid(cls.discover(name=name))))
459459
except StopIteration:
460-
raise PackageNotFoundError(name)
460+
raise PackageNotFoundError(name) from None
461461

462462
@classmethod
463463
def discover(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The :py:class:`importlib.metadata.PackageNotFoundError` traceback raised when
2+
``importlib.metadata.Distribution.from_name`` cannot discover a
3+
distribution no longer includes a transient :exc:`StopIteration` exception trace.
4+
5+
Contributed by Bartosz Sławecki in :gh:`140142`.

0 commit comments

Comments
 (0)