summaryrefslogtreecommitdiff
path: root/sphinx/util
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/util')
-rw-r--r--sphinx/util/__init__.py4
-rw-r--r--sphinx/util/compat.py2
-rw-r--r--sphinx/util/console.py5
-rw-r--r--sphinx/util/docfields.py2
-rw-r--r--sphinx/util/docstrings.py4
-rw-r--r--sphinx/util/docutils.py3
-rw-r--r--sphinx/util/fileutil.py2
-rw-r--r--sphinx/util/i18n.py2
-rw-r--r--sphinx/util/images.py2
-rw-r--r--sphinx/util/inspect.py4
-rw-r--r--sphinx/util/jsdump.py4
-rw-r--r--sphinx/util/jsonimpl.py2
-rw-r--r--sphinx/util/logging.py2
-rw-r--r--sphinx/util/matching.py2
-rw-r--r--sphinx/util/nodes.py3
-rw-r--r--sphinx/util/osutil.py2
-rw-r--r--sphinx/util/parallel.py2
-rw-r--r--sphinx/util/tags.py2
-rw-r--r--sphinx/util/template.py1
-rw-r--r--sphinx/util/typing.py24
20 files changed, 54 insertions, 20 deletions
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py
index bfdecbaa0..1c284d2e0 100644
--- a/sphinx/util/__init__.py
+++ b/sphinx/util/__init__.py
@@ -45,7 +45,7 @@ from sphinx.util.matching import patfilter # noqa
if False:
# For type annotation
- from typing import Any, Callable, IO, Iterable, Iterator, Pattern, Sequence, Tuple, Union # NOQA
+ from typing import Any, Callable, Dict, IO, Iterable, Iterator, List, Pattern, Sequence, Set, Tuple, Union # NOQA
logger = logging.getLogger(__name__)
@@ -109,7 +109,7 @@ def get_matching_docs(dirname, suffixes, exclude_matchers=()):
suffixpatterns = ['*' + s for s in suffixes]
for filename in get_matching_files(dirname, exclude_matchers):
for suffixpattern in suffixpatterns:
- if fnmatch.fnmatch(filename, suffixpattern): # type: ignore
+ if fnmatch.fnmatch(filename, suffixpattern):
yield filename[:-len(suffixpattern) + 1]
break
diff --git a/sphinx/util/compat.py b/sphinx/util/compat.py
index 42406afe7..e5ca6accb 100644
--- a/sphinx/util/compat.py
+++ b/sphinx/util/compat.py
@@ -22,7 +22,7 @@ docutils_version = tuple(int(x) for x in _du_version.split('.')[:2])
if False:
# For type annotation
- from typing import Any # NOQA
+ from typing import Any, Dict # NOQA
class _DeprecationWrapper(object):
diff --git a/sphinx/util/console.py b/sphinx/util/console.py
index ac3d2282f..5e4a0d321 100644
--- a/sphinx/util/console.py
+++ b/sphinx/util/console.py
@@ -19,6 +19,11 @@ try:
except ImportError:
colorama = None
+if False:
+ # For type annotation
+ from typing import Dict # NOQA
+
+
_ansi_re = re.compile('\x1b\\[(\\d\\d;){0,2}\\d\\dm')
codes = {} # type: Dict[str, str]
diff --git a/sphinx/util/docfields.py b/sphinx/util/docfields.py
index f0af0c59d..c7f5e01ee 100644
--- a/sphinx/util/docfields.py
+++ b/sphinx/util/docfields.py
@@ -17,7 +17,7 @@ from sphinx import addnodes
if False:
# For type annotation
- from typing import Any, Tuple # NOQA
+ from typing import Any, Dict, List, Tuple # NOQA
from sphinx.domains import Domain # NOQA
diff --git a/sphinx/util/docstrings.py b/sphinx/util/docstrings.py
index e79408da2..4a0a0df49 100644
--- a/sphinx/util/docstrings.py
+++ b/sphinx/util/docstrings.py
@@ -11,6 +11,10 @@
import sys
+if False:
+ # For type annotation
+ from typing import List # NOQA
+
def prepare_docstring(s, ignore=1):
# type: (unicode, int) -> List[unicode]
diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py
index d9bc64bf3..165d5862a 100644
--- a/sphinx/util/docutils.py
+++ b/sphinx/util/docutils.py
@@ -24,10 +24,9 @@ logger = logging.getLogger(__name__)
report_re = re.compile('^(.+?:\\d+): \\((DEBUG|INFO|WARNING|ERROR|SEVERE)/(\\d+)?\\) '
'(.+?)\n?$')
-
if False:
# For type annotation
- from typing import Any, Callable, Iterator, Tuple # NOQA
+ from typing import Any, Callable, Iterator, List, Tuple # NOQA
from docutils import nodes # NOQA
from sphinx.environment import BuildEnvironment # NOQA
diff --git a/sphinx/util/fileutil.py b/sphinx/util/fileutil.py
index ddfb61e6b..58ed49068 100644
--- a/sphinx/util/fileutil.py
+++ b/sphinx/util/fileutil.py
@@ -18,7 +18,7 @@ from sphinx.util.osutil import copyfile, ensuredir, walk
if False:
# For type annotation
- from typing import Callable, Union # NOQA
+ from typing import Callable, Dict, Union # NOQA
from sphinx.util.matching import Matcher # NOQA
from sphinx.util.template import BaseRenderer # NOQA
diff --git a/sphinx/util/i18n.py b/sphinx/util/i18n.py
index bb6896080..e338824d5 100644
--- a/sphinx/util/i18n.py
+++ b/sphinx/util/i18n.py
@@ -28,7 +28,7 @@ logger = logging.getLogger(__name__)
if False:
# For type annotation
- from typing import Callable # NOQA
+ from typing import Callable, List, Set # NOQA
from sphinx.environment import BuildEnvironment # NOQA
LocaleFileInfoBase = namedtuple('CatalogInfo', 'base_dir,domain,charset')
diff --git a/sphinx/util/images.py b/sphinx/util/images.py
index 81dfaf681..653742c1a 100644
--- a/sphinx/util/images.py
+++ b/sphinx/util/images.py
@@ -23,7 +23,7 @@ except ImportError:
if False:
# For type annotation
- from typing import Tuple # NOQA
+ from typing import Dict, List, Tuple # NOQA
mime_suffixes = {
'.pdf': 'application/pdf',
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
index 58e750a53..4653197b3 100644
--- a/sphinx/util/inspect.py
+++ b/sphinx/util/inspect.py
@@ -12,13 +12,13 @@
import re
from six import PY3, binary_type
-from six.moves import builtins # type: ignore
+from six.moves import builtins
from sphinx.util import force_decode
if False:
# For type annotation
- from typing import Any, Callable, Tuple, Type # NOQA
+ from typing import Any, Callable, List, Tuple, Type # NOQA
# this imports the standard library inspect module without resorting to
# relatively import this module
diff --git a/sphinx/util/jsdump.py b/sphinx/util/jsdump.py
index 592a4565f..9f3b83adf 100644
--- a/sphinx/util/jsdump.py
+++ b/sphinx/util/jsdump.py
@@ -18,7 +18,7 @@ from sphinx.util.pycompat import u
if False:
# For type annotation
- from typing import Any, IO, Match, Union # NOQA
+ from typing import Any, Dict, IO, List, Match, Union # NOQA
_str_re = re.compile(r'"(\\\\|\\"|[^"])*"')
_int_re = re.compile(r'\d+')
@@ -124,7 +124,7 @@ def loads(x):
i = 0
n = len(x)
stack = [] # type: List[Union[List, Dict]]
- obj = nothing
+ obj = nothing # type: Any
key = False
keys = []
while i < n:
diff --git a/sphinx/util/jsonimpl.py b/sphinx/util/jsonimpl.py
index e5f6a0e72..08df7f570 100644
--- a/sphinx/util/jsonimpl.py
+++ b/sphinx/util/jsonimpl.py
@@ -29,7 +29,7 @@ class SphinxJSONEncoder(json.JSONEncoder):
def dump(obj, fp, *args, **kwds):
- # type: (Any, IO, Any, Any) -> unicode
+ # type: (Any, IO, Any, Any) -> None
kwds['cls'] = SphinxJSONEncoder
json.dump(obj, fp, *args, **kwds)
diff --git a/sphinx/util/logging.py b/sphinx/util/logging.py
index 8fd05dbb9..9aca592d7 100644
--- a/sphinx/util/logging.py
+++ b/sphinx/util/logging.py
@@ -24,7 +24,7 @@ from sphinx.util.console import colorize
if False:
# For type annotation
- from typing import Any, Generator, IO, Tuple, Union # NOQA
+ from typing import Any, Dict, Generator, IO, List, Tuple, Union # NOQA
from docutils import nodes # NOQA
from sphinx.application import Sphinx # NOQA
diff --git a/sphinx/util/matching.py b/sphinx/util/matching.py
index be4bfee34..a643f4505 100644
--- a/sphinx/util/matching.py
+++ b/sphinx/util/matching.py
@@ -13,7 +13,7 @@ import re
if False:
# For type annotation
- from typing import Callable, Match, Pattern # NOQA
+ from typing import Callable, Dict, List, Match, Pattern # NOQA
def _translate_pattern(pat):
diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py
index 6bf47da1f..99826f657 100644
--- a/sphinx/util/nodes.py
+++ b/sphinx/util/nodes.py
@@ -22,7 +22,7 @@ from sphinx.util import logging
if False:
# For type annotation
- from typing import Any, Callable, Iterable, Tuple, Union # NOQA
+ from typing import Any, Callable, Iterable, List, Set, Tuple, Union # NOQA
from sphinx.builders import Builder # NOQA
from sphinx.utils.tags import Tags # NOQA
@@ -182,6 +182,7 @@ def find_source_node(node):
for pnode in traverse_parent(node):
if pnode.source:
return pnode.source
+ return None
def traverse_parent(node, cls=None):
diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py
index acf236027..299f2d272 100644
--- a/sphinx/util/osutil.py
+++ b/sphinx/util/osutil.py
@@ -25,7 +25,7 @@ from six import PY2, PY3, text_type
if False:
# For type annotation
- from typing import Any, Iterator, Tuple, Union # NOQA
+ from typing import Any, Iterator, List, Tuple, Union # NOQA
# Errnos that we need.
EEXIST = getattr(errno, 'EEXIST', 0)
diff --git a/sphinx/util/parallel.py b/sphinx/util/parallel.py
index fc691bee1..c7bc1f367 100644
--- a/sphinx/util/parallel.py
+++ b/sphinx/util/parallel.py
@@ -25,7 +25,7 @@ from sphinx.util import logging
if False:
# For type annotation
- from typing import Any, Callable, Sequence # NOQA
+ from typing import Any, Callable, Dict, List, Sequence # NOQA
logger = logging.getLogger(__name__)
diff --git a/sphinx/util/tags.py b/sphinx/util/tags.py
index 18df4f9c3..fe6c9a769 100644
--- a/sphinx/util/tags.py
+++ b/sphinx/util/tags.py
@@ -16,7 +16,7 @@ env = Environment()
if False:
# For type annotation
- from typing import Iterator # NOQA
+ from typing import Iterator, List # NOQA
class BooleanParser(Parser):
diff --git a/sphinx/util/template.py b/sphinx/util/template.py
index 7dee0d71c..1099a2602 100644
--- a/sphinx/util/template.py
+++ b/sphinx/util/template.py
@@ -18,6 +18,7 @@ from sphinx.locale import get_translator
if False:
# For type annotation
+ from typing import Dict # NOQA
from jinja2.loaders import BaseLoader # NOQA
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py
new file mode 100644
index 000000000..20c8883e4
--- /dev/null
+++ b/sphinx/util/typing.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+"""
+ sphinx.util.typing
+ ~~~~~~~~~~~~~~~~~~
+
+ The composit types for Sphinx.
+
+ :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+from six import PY3
+from typing import Callable, Dict, List, Tuple
+
+from docutils import nodes
+from docutils.parsers.rst.states import Inliner
+
+
+if PY3:
+ unicode = str
+
+# common role functions
+RoleFunction = Callable[[unicode, unicode, unicode, int, Inliner, Dict, List[unicode]],
+ Tuple[List[nodes.Node], List[nodes.Node]]]