autosummary: Filter invalid import prefixes in `autolink` (#12626)

This commit is contained in:
Adam Turner
2024-07-20 15:19:55 +01:00
committed by GitHub
parent 6c486a575c
commit bbc97e0357
2 changed files with 11 additions and 2 deletions

View File

@@ -15,6 +15,8 @@ Bugs fixed
``sphinx.ext.autodoc``,
especially when using :mod:`dataclasses` as type metadata.
Patch by Adam Turner.
* #12589, #12626: autosummary: Fix warnings with :rst:role:`!autolink`.
Patch by Adam Turner.
Release 7.4.6 (released Jul 18, 2024)
=====================================
@@ -22,7 +24,7 @@ Release 7.4.6 (released Jul 18, 2024)
Bugs fixed
----------
* #12859, #9743, #12609: autosummary: Do not add the package prefix when
* #12589, #9743, #12609: autosummary: Do not add the package prefix when
generating autosummary directives for modules within a package.
Patch by Adam Turner.
* #12613: Reduce log severity for ambiguity detection during inventory loading.

View File

@@ -765,7 +765,14 @@ class AutoLink(SphinxRole):
try:
# try to import object by name
prefixes = get_import_prefixes_from_env(self.env)
import_by_name(pending_xref['reftarget'], prefixes)
name = pending_xref['reftarget']
prefixes = [
prefix
for prefix in prefixes
if prefix is None
or not (name.startswith(f'{prefix}.') or name == prefix)
]
import_by_name(name, prefixes)
except ImportExceptionGroup:
literal = cast(nodes.literal, pending_xref[0])
objects[0] = nodes.emphasis(self.rawtext, literal.astext(),