mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Migrate to py3 style type annotation: sphinx.ext.mathbase
This commit is contained in:
parent
30ddf70742
commit
c0b267b5a6
@ -9,26 +9,24 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
|
from typing import Callable, List, Tuple
|
||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
|
from docutils.nodes import Element, Node
|
||||||
from docutils.parsers.rst.roles import math_role as math_role_base
|
from docutils.parsers.rst.roles import math_role as math_role_base
|
||||||
|
|
||||||
from sphinx.addnodes import math, math_block as displaymath # NOQA # to keep compatibility
|
from sphinx.addnodes import math, math_block as displaymath # NOQA # to keep compatibility
|
||||||
|
from sphinx.application import Sphinx
|
||||||
from sphinx.builders.latex.nodes import math_reference as eqref # NOQA # to keep compatibility
|
from sphinx.builders.latex.nodes import math_reference as eqref # NOQA # to keep compatibility
|
||||||
from sphinx.deprecation import RemovedInSphinx30Warning
|
from sphinx.deprecation import RemovedInSphinx30Warning
|
||||||
from sphinx.directives.patches import MathDirective as MathDirectiveBase
|
from sphinx.directives.patches import MathDirective as MathDirectiveBase
|
||||||
from sphinx.domains.math import MathDomain # NOQA # to keep compatibility
|
from sphinx.domains.math import MathDomain # NOQA # to keep compatibility
|
||||||
from sphinx.domains.math import MathReferenceRole as EqXRefRole # NOQA # to keep compatibility
|
from sphinx.domains.math import MathReferenceRole as EqXRefRole # NOQA # to keep compatibility
|
||||||
|
from sphinx.writers.html import HTMLTranslator
|
||||||
if False:
|
|
||||||
# For type annotation
|
|
||||||
from typing import Callable, Tuple # NOQA
|
|
||||||
from sphinx.application import Sphinx # NOQA
|
|
||||||
from sphinx.writers.html import HTMLTranslator # NOQA
|
|
||||||
|
|
||||||
|
|
||||||
class MathDirective(MathDirectiveBase):
|
class MathDirective(MathDirectiveBase):
|
||||||
def run(self):
|
def run(self) -> List[Node]:
|
||||||
warnings.warn('sphinx.ext.mathbase.MathDirective is moved to '
|
warnings.warn('sphinx.ext.mathbase.MathDirective is moved to '
|
||||||
'sphinx.directives.patches package.',
|
'sphinx.directives.patches package.',
|
||||||
RemovedInSphinx30Warning, stacklevel=2)
|
RemovedInSphinx30Warning, stacklevel=2)
|
||||||
@ -42,8 +40,7 @@ def math_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
|
|||||||
return math_role_base(role, rawtext, text, lineno, inliner, options, content)
|
return math_role_base(role, rawtext, text, lineno, inliner, options, content)
|
||||||
|
|
||||||
|
|
||||||
def get_node_equation_number(writer, node):
|
def get_node_equation_number(writer: HTMLTranslator, node: nodes.math_block) -> str:
|
||||||
# type: (HTMLTranslator, nodes.math_block) -> str
|
|
||||||
warnings.warn('sphinx.ext.mathbase.get_node_equation_number() is moved to '
|
warnings.warn('sphinx.ext.mathbase.get_node_equation_number() is moved to '
|
||||||
'sphinx.util.math package.',
|
'sphinx.util.math package.',
|
||||||
RemovedInSphinx30Warning, stacklevel=2)
|
RemovedInSphinx30Warning, stacklevel=2)
|
||||||
@ -51,8 +48,7 @@ def get_node_equation_number(writer, node):
|
|||||||
return get_node_equation_number(writer, node)
|
return get_node_equation_number(writer, node)
|
||||||
|
|
||||||
|
|
||||||
def wrap_displaymath(text, label, numbering):
|
def wrap_displaymath(text: str, label: str, numbering: bool) -> str:
|
||||||
# type: (str, str, bool) -> str
|
|
||||||
warnings.warn('sphinx.ext.mathbase.wrap_displaymath() is moved to '
|
warnings.warn('sphinx.ext.mathbase.wrap_displaymath() is moved to '
|
||||||
'sphinx.util.math package.',
|
'sphinx.util.math package.',
|
||||||
RemovedInSphinx30Warning, stacklevel=2)
|
RemovedInSphinx30Warning, stacklevel=2)
|
||||||
@ -60,8 +56,7 @@ def wrap_displaymath(text, label, numbering):
|
|||||||
return wrap_displaymath(text, label, numbering)
|
return wrap_displaymath(text, label, numbering)
|
||||||
|
|
||||||
|
|
||||||
def is_in_section_title(node):
|
def is_in_section_title(node: Element) -> bool:
|
||||||
# type: (nodes.Element) -> bool
|
|
||||||
"""Determine whether the node is in a section title"""
|
"""Determine whether the node is in a section title"""
|
||||||
from sphinx.util.nodes import traverse_parent
|
from sphinx.util.nodes import traverse_parent
|
||||||
|
|
||||||
@ -75,8 +70,9 @@ def is_in_section_title(node):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def setup_math(app, htmlinlinevisitors, htmldisplayvisitors):
|
def setup_math(app: Sphinx,
|
||||||
# type: (Sphinx, Tuple[Callable, Callable], Tuple[Callable, Callable]) -> None
|
htmlinlinevisitors: Tuple[Callable, Callable],
|
||||||
|
htmldisplayvisitors: Tuple[Callable, Callable]) -> None:
|
||||||
warnings.warn('setup_math() is deprecated. '
|
warnings.warn('setup_math() is deprecated. '
|
||||||
'Please use app.add_html_math_renderer() instead.',
|
'Please use app.add_html_math_renderer() instead.',
|
||||||
RemovedInSphinx30Warning, stacklevel=2)
|
RemovedInSphinx30Warning, stacklevel=2)
|
||||||
|
Loading…
Reference in New Issue
Block a user