Skip to content

Commit 49027a9

Browse files
authored
Autosummary: Always emit grouped ImportError exceptions (#11380)
1 parent a464c58 commit 49027a9

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Incompatible changes
2424
* #11378: Remove deprecated ``sphinx.util.docutils.is_html5_writer_available()``
2525
function.
2626
* #11379: Make the ``env`` argument to ``Builder`` subclasses required.
27+
* #11380: autosummary: Always emit grouped import exceptions.
2728

2829
Deprecated
2930
----------

sphinx/ext/autosummary/__init__.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import posixpath
5454
import re
5555
import sys
56-
import warnings
5756
from inspect import Parameter
5857
from os import path
5958
from types import ModuleType
@@ -69,7 +68,6 @@
6968
from sphinx import addnodes
7069
from sphinx.application import Sphinx
7170
from sphinx.config import Config
72-
from sphinx.deprecation import RemovedInSphinx70Warning
7371
from sphinx.environment import BuildEnvironment
7472
from sphinx.ext.autodoc import INSTANCEATTR, Documenter
7573
from sphinx.ext.autodoc.directive import DocumenterBridge, Options
@@ -627,17 +625,11 @@ def get_import_prefixes_from_env(env: BuildEnvironment) -> list[str | None]:
627625

628626

629627
def import_by_name(
630-
name: str, prefixes: list[str | None] = [None], grouped_exception: bool = True,
628+
name: str, prefixes: list[str | None] = [None],
631629
) -> tuple[str, Any, Any, str]:
632630
"""Import a Python object that has the given *name*, under one of the
633631
*prefixes*. The first name that succeeds is used.
634632
"""
635-
if grouped_exception is False:
636-
warnings.warn('Using grouped_exception keyword for import_by_name() is not '
637-
'recommended. It will be removed at v7.0. Therefore you should '
638-
'catch ImportExceptionGroup exception instead of ImportError.',
639-
RemovedInSphinx70Warning, stacklevel=2)
640-
641633
tried = []
642634
errors: list[ImportExceptionGroup] = []
643635
for prefix in prefixes:
@@ -646,18 +638,16 @@ def import_by_name(
646638
prefixed_name = '.'.join([prefix, name])
647639
else:
648640
prefixed_name = name
649-
obj, parent, modname = _import_by_name(prefixed_name, grouped_exception)
641+
obj, parent, modname = _import_by_name(prefixed_name, grouped_exception=True)
650642
return prefixed_name, obj, parent, modname
651643
except ImportError:
652644
tried.append(prefixed_name)
653645
except ImportExceptionGroup as exc:
654646
tried.append(prefixed_name)
655647
errors.append(exc)
656648

657-
if grouped_exception:
658-
exceptions: list[BaseException] = sum((e.exceptions for e in errors), [])
659-
raise ImportExceptionGroup('no module named %s' % ' or '.join(tried), exceptions)
660-
raise ImportError('no module named %s' % ' or '.join(tried))
649+
exceptions: list[BaseException] = sum((e.exceptions for e in errors), [])
650+
raise ImportExceptionGroup('no module named %s' % ' or '.join(tried), exceptions)
661651

662652

663653
def _import_by_name(name: str, grouped_exception: bool = True) -> tuple[Any, Any, str]:
@@ -714,7 +704,7 @@ def import_ivar_by_name(name: str, prefixes: list[str | None] = [None],
714704
"""
715705
try:
716706
name, attr = name.rsplit(".", 1)
717-
real_name, obj, parent, modname = import_by_name(name, prefixes, grouped_exception)
707+
real_name, obj, parent, modname = import_by_name(name, prefixes)
718708

719709
# Get ancestors of the object (class.__mro__ includes the class itself as
720710
# the first entry)

0 commit comments

Comments
 (0)