summaryrefslogtreecommitdiff
path: root/sphinx/directives/other.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/directives/other.py')
-rw-r--r--sphinx/directives/other.py65
1 files changed, 34 insertions, 31 deletions
diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py
index ad8be161d..2efca0722 100644
--- a/sphinx/directives/other.py
+++ b/sphinx/directives/other.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
"""
sphinx.directives.other
~~~~~~~~~~~~~~~~~~~~~~~
@@ -8,13 +7,13 @@
"""
import re
+from typing import cast
from docutils import nodes
from docutils.parsers.rst import directives
from docutils.parsers.rst.directives.admonitions import BaseAdmonition
from docutils.parsers.rst.directives.misc import Class
from docutils.parsers.rst.directives.misc import Include as BaseInclude
-from six.moves import range
from sphinx import addnodes
from sphinx.domains.changeset import VersionChange # NOQA # for compatibility
@@ -35,7 +34,7 @@ glob_re = re.compile(r'.*[*?\[].*')
def int_or_nothing(argument):
- # type: (unicode) -> int
+ # type: (str) -> int
if not argument:
return 999
return int(argument)
@@ -166,7 +165,7 @@ class Author(SphinxDirective):
# type: () -> List[nodes.Node]
if not self.config.show_authors:
return []
- para = nodes.paragraph(translatable=False)
+ para = nodes.paragraph(translatable=False) # type: nodes.Element
emph = nodes.emphasis()
para += emph
if self.name == 'sectionauthor':
@@ -178,10 +177,12 @@ class Author(SphinxDirective):
else:
text = _('Author: ')
emph += nodes.Text(text, text)
- inodes, messages = self.state.inline_text(self.arguments[0],
- self.lineno)
+ inodes, messages = self.state.inline_text(self.arguments[0], self.lineno)
emph.extend(inodes)
- return [para] + messages
+
+ ret = [para] # type: List[nodes.Node]
+ ret += messages
+ return ret
class Index(SphinxDirective):
@@ -248,11 +249,13 @@ class Centered(SphinxDirective):
# type: () -> List[nodes.Node]
if not self.arguments:
return []
- subnode = addnodes.centered()
- inodes, messages = self.state.inline_text(self.arguments[0],
- self.lineno)
+ subnode = addnodes.centered() # type: nodes.Element
+ inodes, messages = self.state.inline_text(self.arguments[0], self.lineno)
subnode.extend(inodes)
- return [subnode] + messages
+
+ ret = [subnode] # type: List[nodes.Node]
+ ret += messages
+ return ret
class Acks(SphinxDirective):
@@ -272,8 +275,8 @@ class Acks(SphinxDirective):
self.state.nested_parse(self.content, self.content_offset, node)
if len(node.children) != 1 or not isinstance(node.children[0],
nodes.bullet_list):
- return [self.state.document.reporter.warning(
- '.. acks content is not a list', line=self.lineno)]
+ reporter = self.state.document.reporter
+ return [reporter.warning('.. acks content is not a list', line=self.lineno)]
return [node]
@@ -297,8 +300,8 @@ class HList(SphinxDirective):
self.state.nested_parse(self.content, self.content_offset, node)
if len(node.children) != 1 or not isinstance(node.children[0],
nodes.bullet_list):
- return [self.state.document.reporter.warning(
- '.. hlist content is not a list', line=self.lineno)]
+ reporter = self.state.document.reporter
+ return [reporter.warning('.. hlist content is not a list', line=self.lineno)]
fulllist = node.children[0]
# create a hlist node where the items are distributed
npercol, nmore = divmod(len(fulllist), ncolumns)
@@ -306,11 +309,10 @@ class HList(SphinxDirective):
newnode = addnodes.hlist()
for column in range(ncolumns):
endindex = index + (column < nmore and (npercol + 1) or npercol)
- col = addnodes.hlistcol()
- col += nodes.bullet_list()
- col[0] += fulllist.children[index:endindex]
+ bullet_list = nodes.bullet_list()
+ bullet_list += fulllist.children[index:endindex]
+ newnode += addnodes.hlistcol('', bullet_list)
index = endindex
- newnode += col
return [newnode]
@@ -333,14 +335,15 @@ class Only(SphinxDirective):
# Same as util.nested_parse_with_titles but try to handle nested
# sections which should be raised higher up the doctree.
- surrounding_title_styles = self.state.memo.title_styles
- surrounding_section_level = self.state.memo.section_level
- self.state.memo.title_styles = []
- self.state.memo.section_level = 0
+ memo = self.state.memo # type: Any
+ surrounding_title_styles = memo.title_styles
+ surrounding_section_level = memo.section_level
+ memo.title_styles = []
+ memo.section_level = 0
try:
self.state.nested_parse(self.content, self.content_offset,
- node, match_titles=1)
- title_styles = self.state.memo.title_styles
+ node, match_titles=True)
+ title_styles = memo.title_styles
if (not surrounding_title_styles or
not title_styles or
title_styles[0] not in surrounding_title_styles or
@@ -361,15 +364,15 @@ class Only(SphinxDirective):
# Use these depths to determine where the nested sections should
# be placed in the doctree.
n_sects_to_raise = current_depth - nested_depth + 1
- parent = self.state.parent
+ parent = cast(nodes.Element, self.state.parent)
for i in range(n_sects_to_raise):
if parent.parent:
parent = parent.parent
parent.append(node)
return []
finally:
- self.state.memo.title_styles = surrounding_title_styles
- self.state.memo.section_level = surrounding_section_level
+ memo.title_styles = surrounding_title_styles
+ memo.section_level = surrounding_section_level
class Include(BaseInclude, SphinxDirective):
@@ -383,15 +386,15 @@ class Include(BaseInclude, SphinxDirective):
if self.arguments[0].startswith('<') and \
self.arguments[0].endswith('>'):
# docutils "standard" includes, do not do path processing
- return BaseInclude.run(self)
+ return super().run()
rel_filename, filename = self.env.relfn2path(self.arguments[0])
self.arguments[0] = filename
self.env.note_included(filename)
- return BaseInclude.run(self)
+ return super().run()
def setup(app):
- # type: (Sphinx) -> Dict[unicode, Any]
+ # type: (Sphinx) -> Dict[str, Any]
directives.register_directive('toctree', TocTree)
directives.register_directive('sectionauthor', Author)
directives.register_directive('moduleauthor', Author)