diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2016-11-08 17:47:52 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2016-11-16 12:06:22 +0900 |
commit | 23b1c3d5f203972d1d7a254594f0e7ca4baf7b59 (patch) | |
tree | e0b9f00c15d4c5e732365705e41c33d27ae78bfa /sphinx/builders/devhelp.py | |
parent | 8a06a42c311c58dcab1116e06b3afbc2541f49f1 (diff) | |
download | sphinx-git-23b1c3d5f203972d1d7a254594f0e7ca4baf7b59.tar.gz |
Add type-check annotations to sphinx.builders
Diffstat (limited to 'sphinx/builders/devhelp.py')
-rw-r--r-- | sphinx/builders/devhelp.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/sphinx/builders/devhelp.py b/sphinx/builders/devhelp.py index fd6f3400e..f0b313e7f 100644 --- a/sphinx/builders/devhelp.py +++ b/sphinx/builders/devhelp.py @@ -25,7 +25,12 @@ from sphinx.builders.html import StandaloneHTMLBuilder try: import xml.etree.ElementTree as etree except ImportError: - import lxml.etree as etree + import lxml.etree as etree # type: ignore + +if False: + # For type annotation + from typing import Any # NOQA + from sphinx.application import Sphinx # NOQA class DevhelpBuilder(StandaloneHTMLBuilder): @@ -44,14 +49,17 @@ class DevhelpBuilder(StandaloneHTMLBuilder): embedded = True def init(self): + # type: () -> None StandaloneHTMLBuilder.init(self) self.out_suffix = '.html' self.link_suffix = '.html' def handle_finish(self): + # type: () -> None self.build_devhelp(self.outdir, self.config.devhelp_basename) def build_devhelp(self, outdir, outname): + # type: (unicode, unicode) -> None self.info('dumping devhelp index...') # Basic info @@ -69,6 +77,7 @@ class DevhelpBuilder(StandaloneHTMLBuilder): self.config.master_doc, self, prune_toctrees=False) def write_toc(node, parent): + # type: (nodes.Node, nodes.Node) -> None if isinstance(node, addnodes.compact_paragraph) or \ isinstance(node, nodes.bullet_list): for subnode in node: @@ -82,6 +91,7 @@ class DevhelpBuilder(StandaloneHTMLBuilder): parent.attrib['name'] = node.astext() def istoctree(node): + # type: (nodes.Node) -> bool return isinstance(node, addnodes.compact_paragraph) and \ 'toctree' in node @@ -93,6 +103,7 @@ class DevhelpBuilder(StandaloneHTMLBuilder): index = self.env.create_index(self) def write_index(title, refs, subitems): + # type: (unicode, List[Any], Any) -> None if len(refs) == 0: pass elif len(refs) == 1: @@ -105,7 +116,7 @@ class DevhelpBuilder(StandaloneHTMLBuilder): link=ref[1]) if subitems: - parent_title = re.sub(r'\s*\(.*\)\s*$', '', title) + parent_title = re.sub(r'\s*\(.*\)\s*$', '', title) # type: ignore for subitem in subitems: write_index("%s %s" % (parent_title, subitem[0]), subitem[1], []) @@ -116,11 +127,12 @@ class DevhelpBuilder(StandaloneHTMLBuilder): # Dump the XML file xmlfile = path.join(outdir, outname + '.devhelp.gz') - with gzip.open(xmlfile, 'w') as f: + with gzip.open(xmlfile, 'w') as f: # type: ignore tree.write(f, 'utf-8') def setup(app): + # type: (Sphinx) -> None app.setup_extension('sphinx.builders.html') app.add_builder(DevhelpBuilder) |