Skip to content

Commit 90c8316

Browse files
alexfiklinducer
authored andcommitted
fix: match text to renamed xref for missing-reference
1 parent 849e15b commit 90c8316

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

sphinxconfig.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from os.path import basename as _basename, dirname as _dirname
22

33
# NOTE: these are only imported for type checking
4-
from docutils.nodes import TextElement
4+
from docutils.nodes import Text, TextElement
55
from sphinx.addnodes import pending_xref
66
from sphinx.application import Sphinx
77
from sphinx.environment import BuildEnvironment
@@ -80,7 +80,7 @@ def process_autodoc_missing_reference(
8080
app: Sphinx,
8181
env: BuildEnvironment,
8282
node: pending_xref,
83-
contnode: TextElement
83+
contnode: Text | TextElement
8484
) -> TextElement | None:
8585
"""Fix missing references due to string annotations.
8686
@@ -148,6 +148,15 @@ def setup(app: Sphinx) -> None:
148148
node.attributes["reftype"] = reftype
149149
node.attributes[f"{domain}:module"] = module
150150

151+
if isinstance(contnode, Text):
152+
# NOTE: if the format is "short", we insist on using just the object name.
153+
# This also makes sure that the text matches the reftarget, in case the
154+
# object was renamed somehow (e.g. from `import Object as _Object`).
155+
if app.config.autodoc_typehints_format == "short":
156+
contnode = Text(objname)
157+
else:
158+
contnode = Text(reftarget)
159+
151160
# resolve reference
152161
from sphinx.ext import intersphinx
153162

0 commit comments

Comments
 (0)