From 259c2bb8a6641d4d93731e92b63c907f82f9a9eb Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 2 Mar 2019 14:50:03 +0900 Subject: [PATCH] refactor: Rename find_source_node() to get_node_source() --- CHANGES | 1 + doc/extdev/index.rst | 5 +++++ sphinx/util/nodes.py | 13 +++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index c6ea04e5a..e48e5197d 100644 --- a/CHANGES +++ b/CHANGES @@ -17,6 +17,7 @@ Deprecated * ``sphinx.ext.autodoc.importer.MockLoader`` * ``sphinx.ext.autodoc.importer.mock()`` * ``sphinx.ext.autosummary.autolink_role()`` +* ``sphinx.util.node.find_source_node()`` * ``sphinx.util.i18n.find_catalog()`` * ``sphinx.util.i18n.find_catalog_files()`` * ``sphinx.util.i18n.find_catalog_source_files()`` diff --git a/doc/extdev/index.rst b/doc/extdev/index.rst index 1cae48860..679288c68 100644 --- a/doc/extdev/index.rst +++ b/doc/extdev/index.rst @@ -254,6 +254,11 @@ The following is a list of deprecated interfaces. - 4.0 - ``sphinx.ext.autosummary.AutoLink`` + * - ``sphinx.util.node.find_source_node()`` + - 2.1 + - 4.0 + - ``sphinx.util.node.get_node_source()`` + * - ``sphinx.util.i18n.find_catalog()`` - 2.1 - 4.0 diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py index b0dd13b38..ba54c717e 100644 --- a/sphinx/util/nodes.py +++ b/sphinx/util/nodes.py @@ -9,11 +9,13 @@ """ import re +import warnings from typing import Any, cast from docutils import nodes from sphinx import addnodes +from sphinx.deprecation import RemovedInSphinx40Warning from sphinx.locale import __ from sphinx.util import logging @@ -152,7 +154,7 @@ def apply_source_workaround(node): # workaround: literal_block under bullet list (#4913) if isinstance(node, nodes.literal_block) and node.source is None: - node.source = find_source_node(node) + node.source = get_node_source(node) # workaround: recommonmark-0.2.0 doesn't set rawsource attribute if not node.rawsource: @@ -170,7 +172,7 @@ def apply_source_workaround(node): ))): logger.debug('[i18n] PATCH: %r to have source and line: %s', get_full_module_name(node), repr_domxml(node)) - node.source = find_source_node(node) + node.source = get_node_source(node) node.line = 0 # need fix docutils to get `node.line` return @@ -278,6 +280,13 @@ def extract_messages(doctree): def find_source_node(node): + # type: (nodes.Element) -> str + warnings.warn('find_source_node() is deprecated.', + RemovedInSphinx40Warning) + return get_node_source(node) + + +def get_node_source(node): # type: (nodes.Element) -> str for pnode in traverse_parent(node): if pnode.source: