diff options
Diffstat (limited to 'sphinx/domains/changeset.py')
-rw-r--r-- | sphinx/domains/changeset.py | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/sphinx/domains/changeset.py b/sphinx/domains/changeset.py index ba323b729..1b31e0248 100644 --- a/sphinx/domains/changeset.py +++ b/sphinx/domains/changeset.py @@ -8,8 +8,7 @@ :license: BSD, see LICENSE for details. """ -from collections import namedtuple -from typing import Any, Dict, List, cast +from typing import TYPE_CHECKING, Any, Dict, List, NamedTuple, cast from docutils import nodes from docutils.nodes import Node @@ -18,9 +17,9 @@ from sphinx import addnodes from sphinx.domains import Domain from sphinx.locale import _ from sphinx.util.docutils import SphinxDirective +from sphinx.util.typing import OptionSpec -if False: - # For type annotation +if TYPE_CHECKING: from sphinx.application import Sphinx from sphinx.environment import BuildEnvironment @@ -38,9 +37,13 @@ versionlabel_classes = { } -# TODO: move to typing.NamedTuple after dropping py35 support (see #5958) -ChangeSet = namedtuple('ChangeSet', - ['type', 'docname', 'lineno', 'module', 'descname', 'content']) +class ChangeSet(NamedTuple): + type: str + docname: str + lineno: int + module: str + descname: str + content: str class VersionChange(SphinxDirective): @@ -51,7 +54,7 @@ class VersionChange(SphinxDirective): required_arguments = 1 optional_arguments = 1 final_argument_whitespace = True - option_spec = {} # type: Dict + option_spec: OptionSpec = {} def run(self) -> List[Node]: node = addnodes.versionmodified() @@ -91,7 +94,7 @@ class VersionChange(SphinxDirective): domain = cast(ChangeSetDomain, self.env.get_domain('changeset')) domain.note_changeset(node) - ret = [node] # type: List[Node] + ret: List[Node] = [node] ret += messages return ret @@ -102,9 +105,9 @@ class ChangeSetDomain(Domain): name = 'changeset' label = 'changeset' - initial_data = { + initial_data: Dict = { 'changes': {}, # version -> list of ChangeSet - } # type: Dict + } @property def changesets(self) -> Dict[str, List[ChangeSet]]: |