summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sphinx/domains/__init__.py8
-rw-r--r--sphinx/domains/changeset.py2
-rw-r--r--sphinx/domains/math.py5
-rw-r--r--sphinx/domains/std.py20
-rw-r--r--sphinx/util/typing.py5
5 files changed, 20 insertions, 20 deletions
diff --git a/sphinx/domains/__init__.py b/sphinx/domains/__init__.py
index 4824f4fb0..fe2207d3c 100644
--- a/sphinx/domains/__init__.py
+++ b/sphinx/domains/__init__.py
@@ -17,7 +17,7 @@ from sphinx.locale import _
if False:
# For type annotation
- from typing import Any, Callable, Dict, Iterable, List, Tuple, Type, Union # NOQA
+ from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type, Union # NOQA
from docutils import nodes # NOQA
from docutils.parsers.rst.states import Inliner # NOQA
from sphinx.builders import Builder # NOQA
@@ -149,7 +149,7 @@ class Domain:
#: role name -> a warning message if reference is missing
dangling_warnings = {} # type: Dict[unicode, unicode]
#: node_class -> (enum_node_type, title_getter)
- enumerable_nodes = {} # type: Dict[nodes.Node, Tuple[unicode, Callable]]
+ enumerable_nodes = {} # type: Dict[Type[nodes.Node], Tuple[unicode, Callable]]
#: data value for a fresh environment
initial_data = {} # type: Dict
@@ -201,7 +201,7 @@ class Domain:
self._role2type.setdefault(role, []).append(name)
def role(self, name):
- # type: (unicode) -> Callable
+ # type: (unicode) -> RoleFunction
"""Return a role adapter function that always gives the registered
role its full name ('domain:name') as the first argument.
"""
@@ -212,7 +212,7 @@ class Domain:
fullname = '%s:%s' % (self.name, name)
def role_adapter(typ, rawtext, text, lineno, inliner, options={}, content=[]):
- # type: (unicode, unicode, unicode, int, Inliner, Dict, List[unicode]) -> nodes.Node # NOQA
+ # type: (unicode, unicode, unicode, int, Inliner, Optional[Dict], Optional[List[unicode]]) -> Tuple[List[nodes.Node], List[nodes.Node]] # NOQA
return self.roles[name](fullname, rawtext, text, lineno,
inliner, options, content)
self._role_cache[name] = role_adapter
diff --git a/sphinx/domains/changeset.py b/sphinx/domains/changeset.py
index 669d8c5b7..2f6d030d6 100644
--- a/sphinx/domains/changeset.py
+++ b/sphinx/domains/changeset.py
@@ -63,7 +63,7 @@ class VersionChange(SphinxDirective):
def run(self):
# type: () -> List[nodes.Node]
- node = addnodes.versionmodified()
+ node = addnodes.versionmodified() # type: nodes.Node
node.document = self.state.document
set_source_info(self, node)
node['type'] = self.name
diff --git a/sphinx/domains/math.py b/sphinx/domains/math.py
index d56f45e0e..b5665f0af 100644
--- a/sphinx/domains/math.py
+++ b/sphinx/domains/math.py
@@ -21,11 +21,10 @@ from sphinx.util.nodes import make_refnode
if False:
# For type annotation
- from typing import Any, Callable, Dict, Iterable, List, Tuple, Union # NOQA
+ from typing import Any, Callable, Dict, Iterable, List, Tuple, Type, Union # NOQA
from sphinx.application import Sphinx # NOQA
from sphinx.builders import Builder # NOQA
from sphinx.environment import BuildEnvironment # NOQA
- from sphinx.util.typing import RoleFunction # NOQA
logger = logging.getLogger(__name__)
@@ -52,7 +51,7 @@ class MathDomain(Domain):
enumerable_nodes = { # node_class -> (figtype, title_getter)
displaymath: ('displaymath', None),
nodes.math_block: ('displaymath', None),
- } # type: Dict[nodes.Node, Tuple[unicode, Callable]]
+ } # type: Dict[Type[nodes.Node], Tuple[unicode, Callable]]
roles = {
'numref': MathReferenceRole(),
}
diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py
index 8cc0adb7f..e688a5939 100644
--- a/sphinx/domains/std.py
+++ b/sphinx/domains/std.py
@@ -16,7 +16,7 @@ from copy import copy
from docutils import nodes
from docutils.parsers.rst import directives
-from docutils.statemachine import ViewList
+from docutils.statemachine import StringList
from sphinx import addnodes
from sphinx.deprecation import RemovedInSphinx30Warning
@@ -127,7 +127,7 @@ class Target(SphinxDirective):
targetname = '%s-%s' % (self.name, fullname)
node = nodes.target('', '', ids=[targetname])
self.state.document.note_explicit_target(node)
- ret = [node]
+ ret = [node] # type: List[nodes.Node]
if self.indextemplate:
indexentry = self.indextemplate % (fullname,)
indextype = 'single'
@@ -294,7 +294,7 @@ class Glossary(SphinxDirective):
# be* a definition list.
# first, collect single entries
- entries = [] # type: List[Tuple[List[Tuple[unicode, unicode, int]], ViewList]]
+ entries = [] # type: List[Tuple[List[Tuple[unicode, unicode, int]], StringList]]
in_definition = True
was_empty = True
messages = []
@@ -316,7 +316,7 @@ class Glossary(SphinxDirective):
messages.append(self.state.reporter.system_message(
2, 'glossary term must be preceded by empty line',
source=source, line=lineno))
- entries.append(([(line, source, lineno)], ViewList()))
+ entries.append(([(line, source, lineno)], StringList()))
in_definition = False
# second term and following
else:
@@ -346,9 +346,9 @@ class Glossary(SphinxDirective):
# now, parse all the entries into a big definition list
items = []
for terms, definition in entries:
- termtexts = []
- termnodes = []
- system_messages = [] # type: List[unicode]
+ termtexts = [] # type: List[unicode]
+ termnodes = [] # type: List[nodes.Node]
+ system_messages = [] # type: List[nodes.Node]
for line, source, lineno in terms:
parts = split_term_classifiers(line)
# parse the term with inline markup
@@ -385,7 +385,7 @@ class Glossary(SphinxDirective):
def token_xrefs(text):
# type: (unicode) -> List[nodes.Node]
- retnodes = []
+ retnodes = [] # type: List[nodes.Node]
pos = 0
for m in token_re.finditer(text):
if m.start() > pos:
@@ -415,7 +415,7 @@ class ProductionList(SphinxDirective):
def run(self):
# type: () -> List[nodes.Node]
objects = self.env.domaindata['std']['objects']
- node = addnodes.productionlist()
+ node = addnodes.productionlist() # type: nodes.Node
messages = [] # type: List[nodes.Node]
i = 0
@@ -520,7 +520,7 @@ class StandardDomain(Domain):
nodes.figure: ('figure', None),
nodes.table: ('table', None),
nodes.container: ('code-block', None),
- } # type: Dict[nodes.Node, Tuple[unicode, Callable]]
+ } # type: Dict[Type[nodes.Node], Tuple[unicode, Callable]]
def __init__(self, env):
# type: (BuildEnvironment) -> None
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py
index d31fa7c68..609de302d 100644
--- a/sphinx/util/typing.py
+++ b/sphinx/util/typing.py
@@ -9,7 +9,7 @@
:license: BSD, see LICENSE for details.
"""
-from typing import Callable, Dict, List, Tuple
+from typing import Callable, Dict, List, Optional, Tuple
from docutils import nodes
from docutils.parsers.rst.states import Inliner
@@ -17,7 +17,8 @@ from six import text_type
# common role functions
-RoleFunction = Callable[[text_type, text_type, text_type, int, Inliner, Dict, List[text_type]],
+RoleFunction = Callable[[text_type, text_type, text_type, int, Inliner,
+ Optional[Dict], Optional[List[text_type]]],
Tuple[List[nodes.Node], List[nodes.Node]]]
# title getter functions for enumerable nodes (see sphinx.domains.std)