summaryrefslogtreecommitdiff
path: root/sphinx/util/docutils.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2016-11-09 11:45:12 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2016-11-16 12:06:21 +0900
commit8cfb281b05653a32f480799cb39d4c7532d27f05 (patch)
tree95d99d97c2cd6f921644c7adbe071705491edf09 /sphinx/util/docutils.py
parentdb732ac0b839a028a868a180550bb4f55d6e9b4b (diff)
downloadsphinx-git-8cfb281b05653a32f480799cb39d4c7532d27f05.tar.gz
Add type-check annotations to sphinx.util
Diffstat (limited to 'sphinx/util/docutils.py')
-rw-r--r--sphinx/util/docutils.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py
index be9e2edad..a18d0b560 100644
--- a/sphinx/util/docutils.py
+++ b/sphinx/util/docutils.py
@@ -12,11 +12,19 @@ from __future__ import absolute_import
from copy import copy
from contextlib import contextmanager
+
from docutils.parsers.rst import directives, roles
+if False:
+ # For type annotation
+ from typing import Any, Callable, Iterator, Tuple # NOQA
+ from docutils import nodes # NOQA
+ from sphinx.environment import BuildEnvironment # NOQA
+
@contextmanager
def docutils_namespace():
+ # type: () -> Iterator[None]
"""Create namespace for reST parsers."""
try:
_directives = copy(directives._directives)
@@ -37,9 +45,10 @@ class sphinx_domains(object):
markup takes precedence.
"""
def __init__(self, env):
+ # type: (BuildEnvironment) -> None
self.env = env
- self.directive_func = None
- self.roles_func = None
+ self.directive_func = None # type: Callable
+ self.roles_func = None # type: Callable
def __enter__(self):
self.enable()
@@ -59,6 +68,7 @@ class sphinx_domains(object):
roles.role = self.role_func
def lookup_domain_element(self, type, name):
+ # type: (unicode, unicode) -> Tuple[Any, List]
"""Lookup a markup element (directive or role), given its name which can
be a full name (with domain).
"""
@@ -87,12 +97,14 @@ class sphinx_domains(object):
raise ElementLookupError
def lookup_directive(self, name, lang_module, document):
+ # type: (unicode, unicode, nodes.document) -> Tuple[Any, List]
try:
return self.lookup_domain_element('directive', name)
except ElementLookupError:
return self.directive_func(name, lang_module, document)
def lookup_role(self, name, lang_module, lineno, reporter):
+ # type: (unicode, unicode, int, Any) -> Tuple[Any, List]
try:
return self.lookup_domain_element('role', name)
except ElementLookupError: