Skip to content

Commit 0bdfa74

Browse files
authored
Use PEP 654 ExceptionGroup for autosummary import errors (#14075)
1 parent 19acb6f commit 0bdfa74

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ Features added
7676
This is useful for links to websites that normalise URL casing (e.g. GitHub)
7777
or case-insensitive servers.
7878
Patch by Fazeel Usmani and James Addison.
79+
* #14075: autosummary: Provide more context in import exception stack traces.
80+
Patch by Philipp A.
7981

8082
Bugs fixed
8183
----------

sphinx/ext/autosummary/__init__.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -610,18 +610,12 @@ def limited_join(
610610
# -- Importing items -----------------------------------------------------------
611611

612612

613-
class ImportExceptionGroup(Exception):
613+
class ImportExceptionGroup(BaseExceptionGroup):
614614
"""Exceptions raised during importing the target objects.
615615
616-
It contains an error messages and a list of exceptions as its arguments.
616+
It contains an error message and a list of exceptions as its arguments.
617617
"""
618618

619-
def __init__(
620-
self, message: str | None, exceptions: Sequence[BaseException]
621-
) -> None:
622-
super().__init__(message)
623-
self.exceptions = list(exceptions)
624-
625619

626620
def get_import_prefixes_from_env(env: BuildEnvironment) -> list[str | None]:
627621
"""Obtain current Python import prefixes (for `import_by_name`)
@@ -684,7 +678,8 @@ def import_by_name(
684678
exceptions: list[BaseException] = functools.reduce(
685679
operator.iadd, (e.exceptions for e in errors), []
686680
)
687-
raise ImportExceptionGroup('no module named %s' % ' or '.join(tried), exceptions)
681+
msg = f'could not import {" or ".join(tried)}'
682+
raise ImportExceptionGroup(msg, exceptions)
688683

689684

690685
def _import_by_name(name: str, grouped_exception: bool = True) -> tuple[Any, Any, str]:

0 commit comments

Comments
 (0)