refactor: Rename find_source_node() to get_node_source()

This commit is contained in:
Takeshi KOMIYA 2019-03-02 14:50:03 +09:00
parent 01f46111c5
commit 259c2bb8a6
3 changed files with 17 additions and 2 deletions

View File

@ -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()``

View File

@ -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

View File

@ -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: