Skip to content

Commit bbc97e0

Browse files
authored
autosummary: Filter invalid import prefixes in autolink (#12626)
1 parent 6c486a5 commit bbc97e0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CHANGES.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ Bugs fixed
1515
``sphinx.ext.autodoc``,
1616
especially when using :mod:`dataclasses` as type metadata.
1717
Patch by Adam Turner.
18+
* #12589, #12626: autosummary: Fix warnings with :rst:role:`!autolink`.
19+
Patch by Adam Turner.
1820

1921
Release 7.4.6 (released Jul 18, 2024)
2022
=====================================
2123

2224
Bugs fixed
2325
----------
2426

25-
* #12859, #9743, #12609: autosummary: Do not add the package prefix when
27+
* #12589, #9743, #12609: autosummary: Do not add the package prefix when
2628
generating autosummary directives for modules within a package.
2729
Patch by Adam Turner.
2830
* #12613: Reduce log severity for ambiguity detection during inventory loading.

sphinx/ext/autosummary/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,14 @@ def run(self) -> tuple[list[Node], list[system_message]]:
765765
try:
766766
# try to import object by name
767767
prefixes = get_import_prefixes_from_env(self.env)
768-
import_by_name(pending_xref['reftarget'], prefixes)
768+
name = pending_xref['reftarget']
769+
prefixes = [
770+
prefix
771+
for prefix in prefixes
772+
if prefix is None
773+
or not (name.startswith(f'{prefix}.') or name == prefix)
774+
]
775+
import_by_name(name, prefixes)
769776
except ImportExceptionGroup:
770777
literal = cast(nodes.literal, pending_xref[0])
771778
objects[0] = nodes.emphasis(self.rawtext, literal.astext(),

0 commit comments

Comments
 (0)