From d0fedc3a4b9f50af53e9f930fdd50deee213a12c Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 6 Jul 2019 12:27:32 +0900 Subject: [PATCH] Migrate to py3 style type annotation: sphinx.environment.collectors.title --- sphinx/environment/collectors/title.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/sphinx/environment/collectors/title.py b/sphinx/environment/collectors/title.py index 0f43eb0af..7d464f874 100644 --- a/sphinx/environment/collectors/title.py +++ b/sphinx/environment/collectors/title.py @@ -8,34 +8,30 @@ :license: BSD, see LICENSE for details. """ +from typing import Any, Dict, Set + from docutils import nodes +from sphinx.application import Sphinx +from sphinx.environment import BuildEnvironment from sphinx.environment.collectors import EnvironmentCollector from sphinx.transforms import SphinxContentsFilter -if False: - # For type annotation - from typing import Dict, Set # NOQA - from sphinx.sphinx import Sphinx # NOQA - from sphinx.environment import BuildEnvironment # NOQA - class TitleCollector(EnvironmentCollector): """title collector for sphinx.environment.""" - def clear_doc(self, app, env, docname): - # type: (Sphinx, BuildEnvironment, str) -> None + def clear_doc(self, app: Sphinx, env: BuildEnvironment, docname: str) -> None: env.titles.pop(docname, None) env.longtitles.pop(docname, None) - def merge_other(self, app, env, docnames, other): - # type: (Sphinx, BuildEnvironment, Set[str], BuildEnvironment) -> None + def merge_other(self, app: Sphinx, env: BuildEnvironment, + docnames: Set[str], other: BuildEnvironment) -> None: for docname in docnames: env.titles[docname] = other.titles[docname] env.longtitles[docname] = other.longtitles[docname] - def process_doc(self, app, doctree): - # type: (Sphinx, nodes.document) -> None + def process_doc(self, app: Sphinx, doctree: nodes.document) -> None: """Add a title node to the document (just copy the first section title), and store that title in the environment. """ @@ -59,8 +55,7 @@ class TitleCollector(EnvironmentCollector): app.env.longtitles[app.env.docname] = longtitlenode -def setup(app): - # type: (Sphinx) -> Dict +def setup(app: Sphinx) -> Dict[str, Any]: app.add_env_collector(TitleCollector) return {