diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-03-06 11:32:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-06 11:32:27 +0300 |
commit | 0a3f897d1523236928e570d16c925a5ad08e1bf0 (patch) | |
tree | 82b26886df2038c109e5b2d752f7558ff679d41a /sphinx/transforms | |
parent | 6886de29f23304457ba7c3cda3ec51e3f53ac208 (diff) | |
parent | 7f0b13af6e023382f8bfdaa0916c614a586ff05c (diff) |
Merge pull request #8432 from tk0miya/7119_pending_xref_condition
Fix #7119: Show type hint names unqualified when resolving succeeded
Diffstat (limited to 'sphinx/transforms')
-rw-r--r-- | sphinx/transforms/post_transforms/__init__.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/sphinx/transforms/post_transforms/__init__.py b/sphinx/transforms/post_transforms/__init__.py index 9ddde5928..b10c25b3e 100644 --- a/sphinx/transforms/post_transforms/__init__.py +++ b/sphinx/transforms/post_transforms/__init__.py @@ -22,10 +22,14 @@ from sphinx.locale import __ from sphinx.transforms import SphinxTransform from sphinx.util import logging from sphinx.util.docutils import SphinxTranslator -from sphinx.util.nodes import process_only_nodes +from sphinx.util.nodes import find_pending_xref_condition, process_only_nodes logger = logging.getLogger(__name__) +if False: + # For type annotation + from docutils.nodes import Node + class SphinxPostTransform(SphinxTransform): """A base class of post-transforms. @@ -97,8 +101,21 @@ class ReferencesResolver(SphinxPostTransform): if newnode is None: self.warn_missing_reference(refdoc, typ, target, node, domain) except NoUri: - newnode = contnode - node.replace_self(newnode or contnode) + newnode = None + + if newnode: + newnodes = [newnode] # type: List[Node] + else: + newnodes = [contnode] + if newnode is None and isinstance(node[0], addnodes.pending_xref_condition): + matched = find_pending_xref_condition(node, "*") + if matched: + newnodes = matched.children + else: + logger.warning(__('Could not determine the fallback text for the ' + 'cross-reference. Might be a bug.'), location=node) + + node.replace_self(newnodes) def resolve_anyref(self, refdoc: str, node: pending_xref, contnode: Element) -> Element: """Resolve reference generated by the "any" role.""" |