File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from 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
55from sphinx .addnodes import pending_xref
66from sphinx .application import Sphinx
77from 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
You can’t perform that action at this time.
0 commit comments