mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
drop translator-specific unknown_visit calls
Removes the need for various translators from raising a `NotImplementedError` exception when missing support for a specific node type. docutils will already raise [1][2] a `NotImplementedError` exception for these cases. This help reduce the implementation inside Sphinx as well as prevents the possible undesired replication of unknown-node handling with third-party extensions [3]. In most cases, generating a warning message for an unsupported node type can be preferred. Providing an indication that a node is not supported can be easier for a user of Sphinx to understand a limitation of a builder over a generic "not implemented" exception. This commit takes the logging call which is already used by `texinfo` and applies it to the `SphinxTranslator` base class -- which any Sphinx translator implementation can use. [1]: https://repo.or.cz/docutils.git/blob/d169015ee0f412cffd69b33654d8a119d99bc0f3:/docutils/nodes.py#l2048 [2]: https://repo.or.cz/docutils.git/blob/53716a13b48128af6045139d3cd2909f61e7ed8e:/docutils/nodes.py#l1897 [3]: https://github.com/sphinx-doc/sphinx/issues/9921 Signed-off-by: James Knight <james.d.knight@live.com>
This commit is contained in:
parent
edd14783f3
commit
75914c67c7
@ -28,7 +28,7 @@ from docutils.utils import Reporter, unescape
|
|||||||
from packaging import version
|
from packaging import version
|
||||||
|
|
||||||
from sphinx.errors import SphinxError
|
from sphinx.errors import SphinxError
|
||||||
from sphinx.locale import _
|
from sphinx.locale import _, __
|
||||||
from sphinx.util import logging
|
from sphinx.util import logging
|
||||||
from sphinx.util.typing import RoleFunction
|
from sphinx.util.typing import RoleFunction
|
||||||
|
|
||||||
@ -496,6 +496,9 @@ class SphinxTranslator(nodes.NodeVisitor):
|
|||||||
else:
|
else:
|
||||||
super().dispatch_departure(node)
|
super().dispatch_departure(node)
|
||||||
|
|
||||||
|
def unknown_visit(self, node: Node) -> None:
|
||||||
|
logger.warning(__('unknown node type: %r'), node, location=node)
|
||||||
|
|
||||||
|
|
||||||
# cache a vanilla instance of nodes.document
|
# cache a vanilla instance of nodes.document
|
||||||
# Used in new_document() function
|
# Used in new_document() function
|
||||||
|
@ -876,9 +876,6 @@ class HTMLTranslator(SphinxTranslator, BaseTranslator):
|
|||||||
if depart:
|
if depart:
|
||||||
depart(self, node)
|
depart(self, node)
|
||||||
|
|
||||||
def unknown_visit(self, node: Node) -> None:
|
|
||||||
raise NotImplementedError('Unknown node: ' + node.__class__.__name__)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def permalink_text(self) -> str:
|
def permalink_text(self) -> str:
|
||||||
warnings.warn('HTMLTranslator.permalink_text is deprecated.',
|
warnings.warn('HTMLTranslator.permalink_text is deprecated.',
|
||||||
|
@ -811,9 +811,6 @@ class HTML5Translator(SphinxTranslator, BaseTranslator):
|
|||||||
if depart:
|
if depart:
|
||||||
depart(self, node)
|
depart(self, node)
|
||||||
|
|
||||||
def unknown_visit(self, node: Node) -> None:
|
|
||||||
raise NotImplementedError('Unknown node: ' + node.__class__.__name__)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def permalink_text(self) -> str:
|
def permalink_text(self) -> str:
|
||||||
warnings.warn('HTMLTranslator.permalink_text is deprecated.',
|
warnings.warn('HTMLTranslator.permalink_text is deprecated.',
|
||||||
|
@ -2079,9 +2079,6 @@ class LaTeXTranslator(SphinxTranslator):
|
|||||||
def depart_math_reference(self, node: Element) -> None:
|
def depart_math_reference(self, node: Element) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def unknown_visit(self, node: Node) -> None:
|
|
||||||
raise NotImplementedError('Unknown node: ' + node.__class__.__name__)
|
|
||||||
|
|
||||||
|
|
||||||
# FIXME: Workaround to avoid circular import
|
# FIXME: Workaround to avoid circular import
|
||||||
# refs: https://github.com/sphinx-doc/sphinx/issues/5433
|
# refs: https://github.com/sphinx-doc/sphinx/issues/5433
|
||||||
|
@ -462,6 +462,3 @@ class ManualPageTranslator(SphinxTranslator, BaseTranslator):
|
|||||||
|
|
||||||
def depart_math_block(self, node: Element) -> None:
|
def depart_math_block(self, node: Element) -> None:
|
||||||
self.depart_centered(node)
|
self.depart_centered(node)
|
||||||
|
|
||||||
def unknown_visit(self, node: Node) -> None:
|
|
||||||
raise NotImplementedError('Unknown node: ' + node.__class__.__name__)
|
|
||||||
|
@ -1265,10 +1265,6 @@ class TexinfoTranslator(SphinxTranslator):
|
|||||||
logger.warning(__("unimplemented node type: %r"), node,
|
logger.warning(__("unimplemented node type: %r"), node,
|
||||||
location=node)
|
location=node)
|
||||||
|
|
||||||
def unknown_visit(self, node: Node) -> None:
|
|
||||||
logger.warning(__("unknown node type: %r"), node,
|
|
||||||
location=node)
|
|
||||||
|
|
||||||
def unknown_departure(self, node: Node) -> None:
|
def unknown_departure(self, node: Node) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -1189,6 +1189,3 @@ class TextTranslator(SphinxTranslator):
|
|||||||
|
|
||||||
def depart_math_block(self, node: Element) -> None:
|
def depart_math_block(self, node: Element) -> None:
|
||||||
self.end_state()
|
self.end_state()
|
||||||
|
|
||||||
def unknown_visit(self, node: Node) -> None:
|
|
||||||
raise NotImplementedError('Unknown node: ' + node.__class__.__name__)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user