Skip to content

Autosummary import exception message is misleading and missing context #14056

@flying-sheep

Description

@flying-sheep

Is your feature request related to a problem? Please describe.
The ImportExceptionGroup message can be very misleading:

no module named mymodule

is also displayed when mymodule is definitely a module, but there was e.g. some dependency import error.

And then you don’t even get to know what actual errors happened, since the sub-exceptions aren’t visible!

Describe the solution you'd like
Make sphinx.ext.autosummary.ImportExceptionGroup inherit from ExceptionGroup when possible:

if sys.version_info > (3, 11):
    class ImportExceptionGroup(ExceptionGroup):
        """Exceptions raised during importing the target objects.
    
        It contains an error messages and a list of exceptions as its arguments.
        """
else:
    ... # existing code

they share the same API and this will result in all sub-exceptions being displayed.

Also change the error message:

-raise ImportExceptionGroup('no module named %s' % ' or '.join(tried), exceptions)
+raise ImportExceptionGroup('could not import {"or ".join(tried)}', exceptions)

Describe alternatives you've considered
N/A

Additional context

class ImportExceptionGroup(Exception):

raise ImportExceptionGroup('no module named %s' % ' or '.join(tried), exceptions)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions