Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions sphinxconfig.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from os.path import basename as _basename, dirname as _dirname

# NOTE: these are only imported for type checking
from docutils.nodes import TextElement
from docutils.nodes import Text, TextElement
from sphinx.addnodes import pending_xref
from sphinx.application import Sphinx
from sphinx.environment import BuildEnvironment
Expand Down Expand Up @@ -80,7 +80,7 @@ def process_autodoc_missing_reference(
app: Sphinx,
env: BuildEnvironment,
node: pending_xref,
contnode: TextElement
contnode: Text | TextElement
) -> TextElement | None:
"""Fix missing references due to string annotations.

Expand Down Expand Up @@ -148,6 +148,15 @@ def setup(app: Sphinx) -> None:
node.attributes["reftype"] = reftype
node.attributes[f"{domain}:module"] = module

if isinstance(contnode, Text):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an else: breakpoint() here to check if this is ever not a Text and it doesn't seem to be the case.

I initially used TextElement because that's what the signature of domain.resolve_xref asked for below, but that seems to be a bug in the type annotations there.

# NOTE: if the format is "short", we insist on using just the object name.
# This also makes sure that the text matches the reftarget, in case the
# object was renamed somehow (e.g. from `import Object as _Object`).
if app.config.autodoc_typehints_format == "short":
contnode = Text(objname)
else:
contnode = Text(reftarget)

# resolve reference
from sphinx.ext import intersphinx

Expand Down
Loading