summaryrefslogtreecommitdiff
path: root/sphinx/directives/patches.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/directives/patches.py')
-rw-r--r--sphinx/directives/patches.py41
1 files changed, 22 insertions, 19 deletions
diff --git a/sphinx/directives/patches.py b/sphinx/directives/patches.py
index 1c90d5313..ecee2b10c 100644
--- a/sphinx/directives/patches.py
+++ b/sphinx/directives/patches.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
"""
sphinx.directives.patches
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -7,6 +6,8 @@
:license: BSD, see LICENSE for details.
"""
+from typing import cast
+
from docutils import nodes
from docutils.nodes import make_id
from docutils.parsers.rst import directives
@@ -30,18 +31,21 @@ class Figure(images.Figure):
def run(self):
# type: () -> List[nodes.Node]
name = self.options.pop('name', None)
- result = images.Figure.run(self)
+ result = super().run()
if len(result) == 2 or isinstance(result[0], nodes.system_message):
return result
- (figure_node,) = result
+ assert len(result) == 1
+ figure_node = cast(nodes.figure, result[0])
if name:
+ # set ``name`` to figure_node if given
self.options['name'] = name
self.add_name(figure_node)
- # fill lineno using image node
+ # copy lineno from image node
if figure_node.line is None and len(figure_node) == 2:
- figure_node.line = figure_node[1].line
+ caption = cast(nodes.caption, figure_node[1])
+ figure_node.line = caption.line
return [figure_node]
@@ -49,17 +53,17 @@ class Figure(images.Figure):
class Meta(html.Meta, SphinxDirective):
def run(self):
# type: () -> List[nodes.Node]
- result = html.Meta.run(self)
+ result = super().run()
for node in result:
if (isinstance(node, nodes.pending) and
isinstance(node.details['nodes'][0], html.MetaBody.meta)):
meta = node.details['nodes'][0]
meta.source = self.env.doc2path(self.env.docname)
meta.line = self.lineno
- meta.rawcontent = meta['content']
+ meta.rawcontent = meta['content'] # type: ignore
# docutils' meta nodes aren't picklable because the class is nested
- meta.__class__ = addnodes.meta
+ meta.__class__ = addnodes.meta # type: ignore
return result
@@ -70,8 +74,8 @@ class RSTTable(tables.RSTTable):
Only for docutils-0.13 or older version."""
def make_title(self):
- # type: () -> Tuple[nodes.Node, unicode]
- title, message = tables.RSTTable.make_title(self)
+ # type: () -> Tuple[nodes.title, List[nodes.system_message]]
+ title, message = super().make_title()
if title:
set_source_info(self, title)
@@ -84,8 +88,8 @@ class CSVTable(tables.CSVTable):
Only for docutils-0.13 or older version."""
def make_title(self):
- # type: () -> Tuple[nodes.Node, unicode]
- title, message = tables.CSVTable.make_title(self)
+ # type: () -> Tuple[nodes.title, List[nodes.system_message]]
+ title, message = super().make_title()
if title:
set_source_info(self, title)
@@ -98,8 +102,8 @@ class ListTable(tables.ListTable):
Only for docutils-0.13 or older version."""
def make_title(self):
- # type: () -> Tuple[nodes.Node, unicode]
- title, message = tables.ListTable.make_title(self)
+ # type: () -> Tuple[nodes.title, List[nodes.system_message]]
+ title, message = super().make_title()
if title:
set_source_info(self, title)
@@ -107,7 +111,6 @@ class ListTable(tables.ListTable):
class MathDirective(SphinxDirective):
-
has_content = True
required_arguments = 0
optional_arguments = 1
@@ -124,18 +127,18 @@ class MathDirective(SphinxDirective):
if self.arguments and self.arguments[0]:
latex = self.arguments[0] + '\n\n' + latex
node = nodes.math_block(latex, latex,
- docname=self.state.document.settings.env.docname,
+ docname=self.env.docname,
number=self.options.get('name'),
label=self.options.get('label'),
nowrap='nowrap' in self.options)
- ret = [node]
+ ret = [node] # type: List[nodes.Node]
set_source_info(self, node)
self.add_target(ret)
return ret
def add_target(self, ret):
# type: (List[nodes.Node]) -> None
- node = ret[0]
+ node = cast(nodes.math_block, ret[0])
# assign label automatically if math_number_all enabled
if node['label'] == '' or (self.config.math_number_all and not node['label']):
@@ -158,7 +161,7 @@ class MathDirective(SphinxDirective):
self.state.document.note_explicit_target(target)
ret.insert(0, target)
except UserWarning as exc:
- self.state_machine.reporter.warning(exc.args[0], line=self.lineno)
+ self.state_machine.reporter.warning(exc, line=self.lineno)
def setup(app):