mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Migrate to py3 style type annotation: sphinx.environment.collectors.title
This commit is contained in:
parent
58847682cc
commit
d0fedc3a4b
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user