diff options
Diffstat (limited to 'sphinx/directives/other.py')
-rw-r--r-- | sphinx/directives/other.py | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py index 5863541bf..1113e8241 100644 --- a/sphinx/directives/other.py +++ b/sphinx/directives/other.py @@ -7,9 +7,11 @@ """ import re +from typing import Any, Dict, List from typing import cast from docutils import nodes +from docutils.nodes import Element, Node from docutils.parsers.rst import directives from docutils.parsers.rst.directives.admonitions import BaseAdmonition from docutils.parsers.rst.directives.misc import Class @@ -25,15 +27,13 @@ from sphinx.util.nodes import explicit_title_re, process_index_entry if False: # For type annotation - from typing import Any, Dict, List # NOQA - from sphinx.application import Sphinx # NOQA + from sphinx.application import Sphinx glob_re = re.compile(r'.*[*?\[].*') -def int_or_nothing(argument): - # type: (str) -> int +def int_or_nothing(argument: str) -> int: if not argument: return 999 return int(argument) @@ -60,8 +60,7 @@ class TocTree(SphinxDirective): 'reversed': directives.flag, } - def run(self): - # type: () -> List[nodes.Node] + def run(self) -> List[Node]: subnode = addnodes.toctree() subnode['parent'] = self.env.docname @@ -160,11 +159,10 @@ class Author(SphinxDirective): final_argument_whitespace = True option_spec = {} # type: Dict - def run(self): - # type: () -> List[nodes.Node] + def run(self) -> List[Node]: if not self.config.show_authors: return [] - para = nodes.paragraph(translatable=False) # type: nodes.Element + para = nodes.paragraph(translatable=False) # type: Element emph = nodes.emphasis() para += emph if self.name == 'sectionauthor': @@ -179,7 +177,7 @@ class Author(SphinxDirective): inodes, messages = self.state.inline_text(self.arguments[0], self.lineno) emph.extend(inodes) - ret = [para] # type: List[nodes.Node] + ret = [para] # type: List[Node] ret += messages return ret @@ -194,8 +192,7 @@ class Index(SphinxDirective): final_argument_whitespace = True option_spec = {} # type: Dict - def run(self): - # type: () -> List[nodes.Node] + def run(self) -> List[Node]: arguments = self.arguments[0].split('\n') targetid = 'index-%s' % self.env.new_serialno('index') targetnode = nodes.target('', '', ids=[targetid]) @@ -226,8 +223,7 @@ class TabularColumns(SphinxDirective): final_argument_whitespace = True option_spec = {} # type: Dict - def run(self): - # type: () -> List[nodes.Node] + def run(self) -> List[Node]: node = addnodes.tabular_col_spec() node['spec'] = self.arguments[0] self.set_source_info(node) @@ -244,15 +240,14 @@ class Centered(SphinxDirective): final_argument_whitespace = True option_spec = {} # type: Dict - def run(self): - # type: () -> List[nodes.Node] + def run(self) -> List[Node]: if not self.arguments: return [] - subnode = addnodes.centered() # type: nodes.Element + subnode = addnodes.centered() # type: Element inodes, messages = self.state.inline_text(self.arguments[0], self.lineno) subnode.extend(inodes) - ret = [subnode] # type: List[nodes.Node] + ret = [subnode] # type: List[Node] ret += messages return ret @@ -267,8 +262,7 @@ class Acks(SphinxDirective): final_argument_whitespace = False option_spec = {} # type: Dict - def run(self): - # type: () -> List[nodes.Node] + def run(self) -> List[Node]: node = addnodes.acks() node.document = self.state.document self.state.nested_parse(self.content, self.content_offset, node) @@ -291,8 +285,7 @@ class HList(SphinxDirective): 'columns': int, } - def run(self): - # type: () -> List[nodes.Node] + def run(self) -> List[Node]: ncolumns = self.options.get('columns', 2) node = nodes.paragraph() node.document = self.state.document @@ -325,8 +318,7 @@ class Only(SphinxDirective): final_argument_whitespace = True option_spec = {} # type: Dict - def run(self): - # type: () -> List[nodes.Node] + def run(self) -> List[Node]: node = addnodes.only() node.document = self.state.document self.set_source_info(node) @@ -380,8 +372,7 @@ class Include(BaseInclude, SphinxDirective): "correctly", i.e. relative to source directory. """ - def run(self): - # type: () -> List[nodes.Node] + def run(self) -> List[Node]: if self.arguments[0].startswith('<') and \ self.arguments[0].endswith('>'): # docutils "standard" includes, do not do path processing @@ -392,8 +383,7 @@ class Include(BaseInclude, SphinxDirective): return super().run() -def setup(app): - # type: (Sphinx) -> Dict[str, Any] +def setup(app: "Sphinx") -> Dict[str, Any]: directives.register_directive('toctree', TocTree) directives.register_directive('sectionauthor', Author) directives.register_directive('moduleauthor', Author) |