Skip to content

Commit

Permalink
refactor: reduce calls of find_pending_xref_conditions (refs: sphinx-…
Browse files Browse the repository at this point in the history
…doc#9240)

After sphinx-doc#9246, `find_pending_xref_conditions()` should be only called from
intended modules.  At present, the Python Domain is the only module to
call it intendedly.  Therefore, this removes the needless calls of the
utility function from "unintended" modules.
  • Loading branch information
tk0miya committed May 19, 2021
1 parent d2d2d7b commit 092b49e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
4 changes: 0 additions & 4 deletions sphinx/domains/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1363,10 +1363,6 @@ def istyping(s: str) -> bool:

return s in typing.__all__ # type: ignore

content = find_pending_xref_condition(node, 'resolved')
if content:
contnode = content.children[0] # type: ignore

if node.get('refdomain') != 'py':
return None
elif node.get('reftype') in ('class', 'obj') and node.get('reftarget') == 'None':
Expand Down
15 changes: 2 additions & 13 deletions sphinx/ext/intersphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
from sphinx.locale import _, __
from sphinx.util import logging, requests
from sphinx.util.inventory import InventoryFile
from sphinx.util.nodes import find_pending_xref_condition
from sphinx.util.typing import Inventory

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -287,16 +286,6 @@ def missing_reference(app: Sphinx, env: BuildEnvironment, node: pending_xref,
# Since Sphinx-2.1, properties are stored as py:method
objtypes.append('py:method')

# determine the contnode by pending_xref_condition
content = find_pending_xref_condition(node, 'resolved')
if content:
# resolved condition found.
contnodes = content.children
contnode = content.children[0] # type: ignore
else:
# not resolved. Use the given contnode
contnodes = [contnode]

to_try = [(inventories.main_inventory, target)]
if domain:
full_qualified_name = env.get_domain(domain).get_full_qualified_name(node)
Expand Down Expand Up @@ -329,7 +318,7 @@ def missing_reference(app: Sphinx, env: BuildEnvironment, node: pending_xref,
newnode = nodes.reference('', '', internal=False, refuri=uri, reftitle=reftitle)
if node.get('refexplicit'):
# use whatever title was given
newnode.extend(contnodes)
newnode.append(contnode)
elif dispname == '-' or \
(domain == 'std' and node['reftype'] == 'keyword'):
# use whatever title was given, but strip prefix
Expand All @@ -338,7 +327,7 @@ def missing_reference(app: Sphinx, env: BuildEnvironment, node: pending_xref,
newnode.append(contnode.__class__(title[len(in_set) + 1:],
title[len(in_set) + 1:]))
else:
newnode.extend(contnodes)
newnode.append(contnode)
else:
# else use the given display name (used for :ref:)
newnode.append(contnode.__class__(dispname, dispname))
Expand Down

0 comments on commit 092b49e

Please sign in to comment.