From 5a8dec457a755ec95eb807b7dc483c8628e64103 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 20 May 2021 02:10:43 +0900 Subject: [PATCH] refactor: reduce calls of find_pending_xref_conditions (refs: #9240) After #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. --- sphinx/domains/python.py | 4 ---- sphinx/ext/intersphinx.py | 15 ++------------- tests/test_ext_intersphinx.py | 8 -------- 3 files changed, 2 insertions(+), 25 deletions(-) diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index 7d39d80edc4..2a66f072453 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -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': diff --git a/sphinx/ext/intersphinx.py b/sphinx/ext/intersphinx.py index 5c6af2dfb75..0797a7c7cdd 100644 --- a/sphinx/ext/intersphinx.py +++ b/sphinx/ext/intersphinx.py @@ -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__) @@ -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) @@ -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 @@ -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)) diff --git a/tests/test_ext_intersphinx.py b/tests/test_ext_intersphinx.py index 62456a3f47d..875f1434629 100644 --- a/tests/test_ext_intersphinx.py +++ b/tests/test_ext_intersphinx.py @@ -196,14 +196,6 @@ def test_missing_reference_pydomain(tempdir, app, status, warning): rn = missing_reference(app, app.env, node, contnode) assert rn.astext() == 'Foo.bar' - # pending_xref_condition="resolved" - node = addnodes.pending_xref('', reftarget='Foo.bar', refdomain='py', reftype='attr') - node['py:module'] = 'module1' - node += addnodes.pending_xref_condition('', 'Foo.bar', condition='resolved') - node += addnodes.pending_xref_condition('', 'module1.Foo.bar', condition='*') - rn = missing_reference(app, app.env, node, nodes.Text('dummy-cont-node')) - assert rn.astext() == 'Foo.bar' - def test_missing_reference_stddomain(tempdir, app, status, warning): inv_file = tempdir / 'inventory'