Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Features added
Patch by Jean-François B.
* #13508: Initial support for :pep:`695` type aliases.
Patch by Martin Matouš, Jeremy Maitin-Shepard, and Adam Turner.
* #14075: autosummary: Provide more context in import exception stack traces.
Patch by Philipp A.

Bugs fixed
----------
Expand Down
13 changes: 4 additions & 9 deletions sphinx/ext/autosummary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,18 +610,12 @@ def limited_join(
# -- Importing items -----------------------------------------------------------


class ImportExceptionGroup(Exception):
class ImportExceptionGroup(BaseExceptionGroup):
"""Exceptions raised during importing the target objects.

It contains an error messages and a list of exceptions as its arguments.
It contains an error message and a list of exceptions as its arguments.
"""

def __init__(
self, message: str | None, exceptions: Sequence[BaseException]
) -> None:
super().__init__(message)
self.exceptions = list(exceptions)


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


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