summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-07-13 23:29:38 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-07-13 23:46:17 +0900
commit0c48a28ad7216ee064b0db564745d749c049bfd5 (patch)
tree2bc2f13992c930c00bd3b60ea3e2c27c31e659cd
parent0bc530f1b7b3303e0f53e42010b629d67e79b835 (diff)
downloadsphinx-git-0c48a28ad7216ee064b0db564745d749c049bfd5.tar.gz
Fix type annotation for python 3.5.1
-rw-r--r--sphinx/application.py3
-rw-r--r--sphinx/builders/__init__.py5
-rw-r--r--sphinx/builders/gettext.py5
-rw-r--r--sphinx/builders/html.py9
-rw-r--r--sphinx/builders/xml.py7
-rw-r--r--sphinx/deprecation.py3
-rw-r--r--sphinx/domains/__init__.py3
-rw-r--r--sphinx/domains/python.py14
-rw-r--r--sphinx/domains/std.py5
-rw-r--r--sphinx/environment/collectors/toctree.py8
-rw-r--r--sphinx/ext/autodoc/__init__.py7
-rw-r--r--sphinx/ext/autodoc/directive.py9
-rw-r--r--sphinx/ext/autosummary/__init__.py8
-rw-r--r--sphinx/ext/autosummary/generate.py6
-rw-r--r--sphinx/ext/doctest.py3
-rw-r--r--sphinx/ext/napoleon/docstring.py8
-rw-r--r--sphinx/io.py3
-rw-r--r--sphinx/parsers.py3
-rw-r--r--sphinx/project.py5
-rw-r--r--sphinx/registry.py3
-rw-r--r--sphinx/roles.py3
-rw-r--r--sphinx/search/__init__.py3
-rw-r--r--sphinx/transforms/i18n.py3
-rw-r--r--sphinx/util/__init__.py7
-rw-r--r--sphinx/util/docfields.py7
-rw-r--r--sphinx/util/docutils.py15
-rw-r--r--sphinx/util/logging.py3
-rw-r--r--sphinx/util/nodes.py5
-rw-r--r--sphinx/util/osutil.py8
29 files changed, 115 insertions, 56 deletions
diff --git a/sphinx/application.py b/sphinx/application.py
index a841f52b1..1c7a05357 100644
--- a/sphinx/application.py
+++ b/sphinx/application.py
@@ -48,7 +48,8 @@ from sphinx.util.tags import Tags
if False:
# For type annotation
- from typing import Any, Callable, Dict, IO, Iterable, Iterator, List, Tuple, Type, Union # NOQA
+ from typing import Any, Callable, Dict, IO, Iterable, Iterator, List, Tuple, Union # NOQA
+ from typing import Type # for python3.5.1
from docutils import nodes # NOQA
from docutils.parsers import Parser # NOQA
from docutils.transforms import Transform # NOQA
diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py
index 546b9b0a8..b7e139b60 100644
--- a/sphinx/builders/__init__.py
+++ b/sphinx/builders/__init__.py
@@ -11,7 +11,7 @@
import pickle
import time
from os import path
-from typing import Any, Dict, Iterable, List, Sequence, Set, Tuple, Type, Union
+from typing import Any, Dict, Iterable, List, Sequence, Set, Tuple, Union
from docutils import nodes
from docutils.nodes import Node
@@ -44,6 +44,7 @@ except ImportError:
if False:
# For type annotation
+ from typing import Type # for python3.5.1
from sphinx.application import Sphinx
@@ -117,7 +118,7 @@ class Builder:
self.env.set_versioning_method(self.versioning_method,
self.versioning_compare)
- def get_translator_class(self, *args) -> Type[nodes.NodeVisitor]:
+ def get_translator_class(self, *args) -> "Type[nodes.NodeVisitor]":
"""Return a class of translator."""
return self.app.registry.get_translator_class(self)
diff --git a/sphinx/builders/gettext.py b/sphinx/builders/gettext.py
index 2beb4a5ce..763399413 100644
--- a/sphinx/builders/gettext.py
+++ b/sphinx/builders/gettext.py
@@ -14,7 +14,7 @@ from datetime import datetime, tzinfo, timedelta
from io import StringIO
from os import path, walk, getenv
from time import time
-from typing import Any, DefaultDict, Dict, Iterable, List, Set, Tuple, Union
+from typing import Any, Dict, Iterable, List, Set, Tuple, Union
from uuid import uuid4
from docutils import nodes
@@ -33,6 +33,9 @@ from sphinx.util.nodes import extract_messages, traverse_translatable_index
from sphinx.util.osutil import relpath, ensuredir, canon_path
from sphinx.util.tags import Tags
+if False:
+ # For type annotation
+ from typing import DefaultDict # for python3.5.1
logger = logging.getLogger(__name__)
diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py
index 1a7054bdc..ea005204c 100644
--- a/sphinx/builders/html.py
+++ b/sphinx/builders/html.py
@@ -15,7 +15,7 @@ import sys
import warnings
from hashlib import md5
from os import path
-from typing import Any, Dict, IO, Iterable, Iterator, List, Set, Type, Tuple
+from typing import Any, Dict, IO, Iterable, Iterator, List, Set, Tuple
from docutils import nodes
from docutils.core import publish_parts
@@ -48,6 +48,11 @@ from sphinx.util.osutil import os_path, relative_uri, ensuredir, movefile, copyf
from sphinx.util.tags import Tags
from sphinx.writers.html import HTMLWriter, HTMLTranslator
+if False:
+ # For type annotation
+ from typing import Type # for python3.5.1
+
+
# HTML5 Writer is avialable or not
if is_html5_writer_available():
from sphinx.writers.html5 import HTML5Translator
@@ -331,7 +336,7 @@ class StandaloneHTMLBuilder(Builder):
self.script_files.append(JavaScript(filename, **kwargs))
@property
- def default_translator_class(self) -> Type[nodes.NodeVisitor]: # type: ignore
+ def default_translator_class(self) -> "Type[nodes.NodeVisitor]": # type: ignore
if not html5_ready or self.config.html4_writer:
return HTMLTranslator
else:
diff --git a/sphinx/builders/xml.py b/sphinx/builders/xml.py
index 4aaa0811d..a9f8bfc2c 100644
--- a/sphinx/builders/xml.py
+++ b/sphinx/builders/xml.py
@@ -9,7 +9,7 @@
"""
from os import path
-from typing import Any, Dict, Iterator, Set, Type, Union
+from typing import Any, Dict, Iterator, Set, Union
from docutils import nodes
from docutils.io import StringOutput
@@ -23,6 +23,11 @@ from sphinx.util import logging
from sphinx.util.osutil import ensuredir, os_path
from sphinx.writers.xml import XMLWriter, PseudoXMLWriter
+if False:
+ # For type annotation
+ from typing import Type # for python3.5.1
+
+
logger = logging.getLogger(__name__)
diff --git a/sphinx/deprecation.py b/sphinx/deprecation.py
index be01ca65f..7cdb1d3d1 100644
--- a/sphinx/deprecation.py
+++ b/sphinx/deprecation.py
@@ -14,7 +14,8 @@ from importlib import import_module
if False:
# For type annotation
- from typing import Any, Dict, Type # NOQA
+ from typing import Any, Dict # NOQA
+ from typing import Type # for python3.5.1
class RemovedInSphinx30Warning(DeprecationWarning):
diff --git a/sphinx/domains/__init__.py b/sphinx/domains/__init__.py
index 1fe98950b..a2109d3f7 100644
--- a/sphinx/domains/__init__.py
+++ b/sphinx/domains/__init__.py
@@ -10,7 +10,7 @@
"""
import copy
-from typing import Any, Callable, Dict, Iterable, List, NamedTuple, Tuple, Type, Union
+from typing import Any, Callable, Dict, Iterable, List, NamedTuple, Tuple, Union
from docutils import nodes
from docutils.nodes import Element, Node, system_message
@@ -24,6 +24,7 @@ from sphinx.util.typing import RoleFunction
if False:
# For type annotation
+ from typing import Type # for python3.5.1
from sphinx.builders import Builder
from sphinx.environment import BuildEnvironment
diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py
index b70481198..a2ed21f66 100644
--- a/sphinx/domains/python.py
+++ b/sphinx/domains/python.py
@@ -10,7 +10,7 @@
import re
import warnings
-from typing import Any, Dict, Iterable, Iterator, List, Tuple, Type
+from typing import Any, Dict, Iterable, Iterator, List, Tuple
from typing import cast
from docutils import nodes
@@ -35,6 +35,10 @@ from sphinx.util.docutils import SphinxDirective
from sphinx.util.nodes import make_refnode
from sphinx.util.typing import TextlikeNode
+if False:
+ # For type annotation
+ from typing import Type # for python3.5.1
+
logger = logging.getLogger(__name__)
@@ -119,7 +123,7 @@ def _pseudo_parse_arglist(signode: desc_signature, arglist: str) -> None:
# when it comes to handling "." and "~" prefixes.
class PyXrefMixin:
def make_xref(self, rolename: str, domain: str, target: str,
- innernode: Type[TextlikeNode] = nodes.emphasis,
+ innernode: "Type[TextlikeNode]" = nodes.emphasis,
contnode: Node = None, env: BuildEnvironment = None) -> Node:
result = super().make_xref(rolename, domain, target, # type: ignore
innernode, contnode, env)
@@ -136,7 +140,7 @@ class PyXrefMixin:
return result
def make_xrefs(self, rolename: str, domain: str, target: str,
- innernode: Type[TextlikeNode] = nodes.emphasis,
+ innernode: "Type[TextlikeNode]" = nodes.emphasis,
contnode: Node = None, env: BuildEnvironment = None) -> List[Node]:
delims = r'(\s*[\[\]\(\),](?:\s*or\s)?\s*|\s+or\s+)'
delims_re = re.compile(delims)
@@ -160,7 +164,7 @@ class PyXrefMixin:
class PyField(PyXrefMixin, Field):
def make_xref(self, rolename: str, domain: str, target: str,
- innernode: Type[TextlikeNode] = nodes.emphasis,
+ innernode: "Type[TextlikeNode]" = nodes.emphasis,
contnode: Node = None, env: BuildEnvironment = None) -> Node:
if rolename == 'class' and target == 'None':
# None is not a type, so use obj role instead.
@@ -175,7 +179,7 @@ class PyGroupedField(PyXrefMixin, GroupedField):
class PyTypedField(PyXrefMixin, TypedField):
def make_xref(self, rolename: str, domain: str, target: str,
- innernode: Type[TextlikeNode] = nodes.emphasis,
+ innernode: "Type[TextlikeNode]" = nodes.emphasis,
contnode: Node = None, env: BuildEnvironment = None) -> Node:
if rolename == 'class' and target == 'None':
# None is not a type, so use obj role instead.
diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py
index 6b4820500..98dda4918 100644
--- a/sphinx/domains/std.py
+++ b/sphinx/domains/std.py
@@ -12,7 +12,7 @@ import re
import unicodedata
import warnings
from copy import copy
-from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple, Type, Union
+from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple, Union
from typing import cast
from docutils import nodes
@@ -35,6 +35,7 @@ from sphinx.util.typing import RoleFunction
if False:
# For type annotation
+ from typing import Type # for python3.5.1
from sphinx.application import Sphinx
from sphinx.builders import Builder
from sphinx.environment import BuildEnvironment
@@ -910,7 +911,7 @@ class StandardDomain(Domain):
def get_enumerable_node_type(self, node: Node) -> str:
"""Get type of enumerable nodes."""
- def has_child(node: Element, cls: Type) -> bool:
+ def has_child(node: Element, cls: "Type") -> bool:
return any(isinstance(child, cls) for child in node)
if isinstance(node, nodes.section):
diff --git a/sphinx/environment/collectors/toctree.py b/sphinx/environment/collectors/toctree.py
index d1e211d2c..bacfc4baa 100644
--- a/sphinx/environment/collectors/toctree.py
+++ b/sphinx/environment/collectors/toctree.py
@@ -8,7 +8,7 @@
:license: BSD, see LICENSE for details.
"""
-from typing import Any, Dict, List, Set, Tuple, Type, TypeVar
+from typing import Any, Dict, List, Set, Tuple, TypeVar
from typing import cast
from docutils import nodes
@@ -23,6 +23,10 @@ from sphinx.locale import __
from sphinx.transforms import SphinxContentsFilter
from sphinx.util import url_re, logging
+if False:
+ # For type annotation
+ from typing import Type # for python3.5.1
+
N = TypeVar('N')
@@ -64,7 +68,7 @@ class TocTreeCollector(EnvironmentCollector):
docname = app.env.docname
numentries = [0] # nonlocal again...
- def traverse_in_section(node: Element, cls: Type[N]) -> List[N]:
+ def traverse_in_section(node: Element, cls: "Type[N]") -> List[N]:
"""Like traverse(), but stay within the same section."""
result = [] # type: List[N]
if isinstance(node, cls):
diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py
index f429c25be..d8e93727b 100644
--- a/sphinx/ext/autodoc/__init__.py
+++ b/sphinx/ext/autodoc/__init__.py
@@ -13,7 +13,7 @@
import re
import warnings
from types import ModuleType
-from typing import Any, Callable, Dict, Iterator, List, Sequence, Set, Tuple, Type, Union
+from typing import Any, Callable, Dict, Iterator, List, Sequence, Set, Tuple, Union
from docutils.statemachine import StringList
@@ -38,6 +38,7 @@ from sphinx.util.inspect import (
if False:
# For type annotation
+ from typing import Type # NOQA # for python3.5.1
from sphinx.ext.autodoc.directive import DocumenterBridge
@@ -255,7 +256,7 @@ class Documenter:
self.analyzer = None # type: ModuleAnalyzer
@property
- def documenters(self) -> Dict[str, Type["Documenter"]]:
+ def documenters(self) -> Dict[str, "Type[Documenter]"]:
"""Returns registered Documenter classes"""
return get_documenters(self.env.app)
@@ -1486,7 +1487,7 @@ class SlotsAttributeDocumenter(AttributeDocumenter):
return []
-def get_documenters(app: Sphinx) -> Dict[str, Type[Documenter]]:
+def get_documenters(app: Sphinx) -> Dict[str, "Type[Documenter]"]:
"""Returns registered Documenter classes"""
return app.registry.documenters
diff --git a/sphinx/ext/autodoc/directive.py b/sphinx/ext/autodoc/directive.py
index 953e3c44c..b44bd75b3 100644
--- a/sphinx/ext/autodoc/directive.py
+++ b/sphinx/ext/autodoc/directive.py
@@ -7,7 +7,7 @@
"""
import warnings
-from typing import Any, Callable, Dict, List, Set, Type
+from typing import Any, Callable, Dict, List, Set
from docutils import nodes
from docutils.nodes import Element, Node
@@ -23,6 +23,11 @@ from sphinx.util import logging
from sphinx.util.docutils import SphinxDirective, switch_source_input
from sphinx.util.nodes import nested_parse_with_titles
+if False:
+ # For type annotation
+ from typing import Type # for python3.5.1
+
+
logger = logging.getLogger(__name__)
@@ -70,7 +75,7 @@ class DocumenterBridge:
logger.warning(msg, location=(self.env.docname, self.lineno))
-def process_documenter_options(documenter: Type[Documenter], config: Config, options: Dict
+def process_documenter_options(documenter: "Type[Documenter]", config: Config, options: Dict
) -> Options:
"""Recognize options of Documenter from user input."""
for name in AUTODOC_DEFAULT_OPTIONS:
diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py
index 7c92bb8b5..de8c18baf 100644
--- a/sphinx/ext/autosummary/__init__.py
+++ b/sphinx/ext/autosummary/__init__.py
@@ -60,7 +60,7 @@ import sys
import warnings
from os import path
from types import ModuleType
-from typing import Any, Dict, List, Tuple, Type
+from typing import Any, Dict, List, Tuple
from typing import cast
from docutils import nodes
@@ -88,6 +88,10 @@ from sphinx.util.docutils import (
from sphinx.util.matching import Matcher
from sphinx.writers.html import HTMLTranslator
+if False:
+ # For type annotation
+ from typing import Type # for python3.5.1
+
logger = logging.getLogger(__name__)
@@ -173,7 +177,7 @@ class FakeDirective(DocumenterBridge):
super().__init__({}, None, Options(), 0, state) # type: ignore
-def get_documenter(app: Sphinx, obj: Any, parent: Any) -> Type[Documenter]:
+def get_documenter(app: Sphinx, obj: Any, parent: Any) -> "Type[Documenter]":
"""Get an autodoc.Documenter class suitable for documenting the given
object.
diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py
index 2a23f1289..c4726f528 100644
--- a/sphinx/ext/autosummary/generate.py
+++ b/sphinx/ext/autosummary/generate.py
@@ -24,7 +24,7 @@ import pydoc
import re
import sys
import warnings
-from typing import Any, Callable, Dict, List, Set, Tuple, Type
+from typing import Any, Callable, Dict, List, Set, Tuple
from jinja2 import BaseLoader, FileSystemLoader, TemplateNotFound
from jinja2.sandbox import SandboxedEnvironment
@@ -44,6 +44,10 @@ from sphinx.util import rst
from sphinx.util.inspect import safe_getattr
from sphinx.util.osutil import ensuredir
+if False:
+ # For type annotation
+ from typing import Type # for python3.5.1
+
logger = logging.getLogger(__name__)
diff --git a/sphinx/ext/doctest.py b/sphinx/ext/doctest.py
index 5e4d6681a..391de73b7 100644
--- a/sphinx/ext/doctest.py
+++ b/sphinx/ext/doctest.py
@@ -16,7 +16,7 @@ import time
import warnings
from io import StringIO
from os import path
-from typing import Any, Callable, Dict, Iterable, List, Sequence, Set, Tuple, Type
+from typing import Any, Callable, Dict, Iterable, List, Sequence, Set, Tuple
from docutils import nodes
from docutils.nodes import Element, Node, TextElement
@@ -35,6 +35,7 @@ from sphinx.util.osutil import relpath
if False:
# For type annotation
+ from typing import Type # for python3.5.1
from sphinx.application import Sphinx
diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py
index 097c00e29..5610815bd 100644
--- a/sphinx/ext/napoleon/docstring.py
+++ b/sphinx/ext/napoleon/docstring.py
@@ -13,13 +13,17 @@
import inspect
import re
from functools import partial
-from typing import Any, Callable, Dict, List, Tuple, Type, Union
+from typing import Any, Callable, Dict, List, Tuple, Union
from sphinx.application import Sphinx
from sphinx.config import Config as SphinxConfig
from sphinx.ext.napoleon.iterators import modify_iter
from sphinx.locale import _
+if False:
+ # For type annotation
+ from typing import Type # for python3.5.1
+
_directive_regex = re.compile(r'\.\. \S+::')
_google_section_regex = re.compile(r'^(\s|\w)+:\s*$')
@@ -735,7 +739,7 @@ class GoogleDocstring:
colon,
"".join(after_colon).strip())
- def _qualify_name(self, attr_name: str, klass: Type) -> str:
+ def _qualify_name(self, attr_name: str, klass: "Type") -> str:
if klass and '.' not in attr_name:
if attr_name.startswith('~'):
attr_name = attr_name[1:]
diff --git a/sphinx/io.py b/sphinx/io.py
index 5f4ec3351..5bf2d60da 100644
--- a/sphinx/io.py
+++ b/sphinx/io.py
@@ -35,7 +35,8 @@ from sphinx.versioning import UIDTransform
if False:
# For type annotation
- from typing import Dict, List, Tuple, Type # NOQA
+ from typing import Dict, List, Tuple # NOQA
+ from typing import Type # for python3.5.1
from docutils import nodes # NOQA
from docutils.frontend import Values # NOQA
from docutils.io import Input # NOQA
diff --git a/sphinx/parsers.py b/sphinx/parsers.py
index b974f83e7..f228fb31b 100644
--- a/sphinx/parsers.py
+++ b/sphinx/parsers.py
@@ -18,7 +18,8 @@ from sphinx.util.rst import append_epilog, prepend_prolog
if False:
# For type annotation
- from typing import Any, Dict, List, Type, Union # NOQA
+ from typing import Any, Dict, List, Union # NOQA
+ from typing import Type # for python3.5.1
from docutils import nodes # NOQA
from docutils.transforms import Transform # NOQA
from sphinx.application import Sphinx # NOQA
diff --git a/sphinx/project.py b/sphinx/project.py
index 8e2e7330a..81d2b43e0 100644
--- a/sphinx/project.py
+++ b/sphinx/project.py
@@ -9,7 +9,6 @@
"""
import os
-from typing import TYPE_CHECKING
from sphinx.locale import __
from sphinx.util import get_matching_files
@@ -17,9 +16,11 @@ from sphinx.util import logging
from sphinx.util.matching import compile_matchers
from sphinx.util.osutil import SEP, relpath
-if TYPE_CHECKING:
+if False:
+ # For type annotation
from typing import Dict, List, Set # NOQA
+
logger = logging.getLogger(__name__)
EXCLUDE_PATHS = ['**/_sources', '.#*', '**/.#*', '*.lproj/**']
diff --git a/sphinx/registry.py b/sphinx/registry.py
index 311270ccb..f8ee39466 100644
--- a/sphinx/registry.py
+++ b/sphinx/registry.py
@@ -30,7 +30,8 @@ from sphinx.util.logging import prefixed_warnings
if False:
# For type annotation
- from typing import Any, Callable, Dict, Iterator, List, Tuple, Type, Union # NOQA
+ from typing import Any, Callable, Dict, Iterator, List, Tuple, Union # NOQA
+ from typing import Type # for python3.5.1
from docutils import nodes # NOQA
from docutils.io import Input # NOQA
from docutils.parsers import Parser # NOQA
diff --git a/sphinx/roles.py b/sphinx/roles.py
index 1b80e1ec3..381b9b6f0 100644
--- a/sphinx/roles.py
+++ b/sphinx/roles.py
@@ -23,7 +23,8 @@ from sphinx.util.nodes import split_explicit_title, process_index_entry, \
if False:
# For type annotation
- from typing import Any, Dict, List, Tuple, Type # NOQA
+ from typing import Any, Dict, List, Tuple # NOQA
+ from typing import Type # for python3.5.1
from docutils.parsers.rst.states import Inliner # NOQA
from sphinx.application import Sphinx # NOQA
from sphinx.environment import BuildEnvironment # NOQA
diff --git a/sphinx/search/__init__.py b/sphinx/search/__init__.py
index 868b0e489..1b4f7ea59 100644
--- a/sphinx/search/__init__.py
+++ b/sphinx/search/__init__.py
@@ -23,7 +23,8 @@ from sphinx.util import jsdump, rpartition
if False:
# For type annotation
- from typing import Any, Dict, IO, Iterable, List, Tuple, Type, Set # NOQA
+ from typing import Any, Dict, IO, Iterable, List, Tuple, Set # NOQA
+ from typing import Type # for python3.5.1
from docutils import nodes # NOQA
from sphinx.environment import BuildEnvironment # NOQA
diff --git a/sphinx/transforms/i18n.py b/sphinx/transforms/i18n.py
index c884bb89d..ab2ead8e0 100644
--- a/sphinx/transforms/i18n.py
+++ b/sphinx/transforms/i18n.py
@@ -29,7 +29,8 @@ from sphinx.util.nodes import (
if False:
# For type annotation
- from typing import Dict, List, Tuple, Type # NOQA
+ from typing import Dict, List, Tuple # NOQA
+ from typing import Type # for python3.5.1
from sphinx.application import Sphinx # NOQA
from sphinx.config import Config # NOQA
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py
index e0edb3d33..f06720695 100644
--- a/sphinx/util/__init__.py
+++ b/sphinx/util/__init__.py
@@ -24,9 +24,7 @@ from datetime import datetime
from hashlib import md5
from os import path
from time import mktime, strptime
-from typing import (
- Any, Callable, Dict, IO, Iterable, Iterator, List, Pattern, Set, Tuple, Type
-)
+from typing import Any, Callable, Dict, IO, Iterable, Iterator, List, Pattern, Set, Tuple
from urllib.parse import urlsplit, urlunsplit, quote_plus, parse_qsl, urlencode
from docutils.utils import relative_path
@@ -53,6 +51,7 @@ from sphinx.util.matching import patfilter # noqa
if False:
# For type annotation
+ from typing import Type # for python3.5.1
from sphinx.application import Sphinx
from sphinx.builders import Builder
@@ -655,7 +654,7 @@ class progress_message:
def __enter__(self) -> None:
logger.info(bold(self.message + '... '), nonl=True)
- def __exit__(self, exc_type: Type[Exception], exc_value: Exception, traceback: Any) -> bool: # NOQA
+ def __exit__(self, exc_type: "Type[Exception]", exc_value: Exception, traceback: Any) -> bool: # NOQA
if isinstance(exc_value, SkipProgressMessage):
logger.info(__('skipped'))
if exc_value.args:
diff --git a/sphinx/util/docfields.py b/sphinx/util/docfields.py
index f3729c0c9..1e8596e5b 100644
--- a/sphinx/util/docfields.py
+++ b/sphinx/util/docfields.py
@@ -10,7 +10,7 @@
"""
import warnings
-from typing import Any, Dict, List, Tuple, Type, Union
+from typing import Any, Dict, List, Tuple, Union
from typing import cast
from docutils import nodes
@@ -22,6 +22,7 @@ from sphinx.util.typing import TextlikeNode
if False:
# For type annotation
+ from typing import Type # for python3.5.1
from sphinx.environment import BuildEnvironment
from sphinx.directive import ObjectDescription
@@ -65,7 +66,7 @@ class Field:
self.bodyrolename = bodyrolename
def make_xref(self, rolename: str, domain: str, target: str,
- innernode: Type[TextlikeNode] = addnodes.literal_emphasis,
+ innernode: "Type[TextlikeNode]" = addnodes.literal_emphasis,
contnode: Node = None, env: "BuildEnvironment" = None) -> Node:
if not rolename:
return contnode or innernode(target, target)
@@ -77,7 +78,7 @@ class Field:
return refnode
def make_xrefs(self, rolename: str, domain: str, target: str,
- innernode: Type[TextlikeNode] = addnodes.literal_emphasis,
+ innernode: "Type[TextlikeNode]" = addnodes.literal_emphasis,
contnode: Node = None, env: "BuildEnvironment" = None) -> List[Node]:
return [self.make_xref(rolename, domain, target, innernode, contnode, env)]
diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py
index d0300a682..d4d808968 100644
--- a/sphinx/util/docutils.py
+++ b/sphinx/util/docutils.py
@@ -17,7 +17,7 @@ from copy import copy
from distutils.version import LooseVersion
from os import path
from types import ModuleType
-from typing import Any, Callable, Dict, Generator, IO, List, Optional, Set, Tuple, Type
+from typing import Any, Callable, Dict, Generator, IO, List, Optional, Set, Tuple
from typing import cast
import docutils
@@ -40,6 +40,7 @@ report_re = re.compile('^(.+?:(?:\\d+)?): \\((DEBUG|INFO|WARNING|ERROR|SEVERE)/(
if False:
# For type annotation
+ from typing import Type # for python3.5.1
from sphinx.builders import Builder
from sphinx.config import Config
from sphinx.environment import BuildEnvironment
@@ -71,7 +72,7 @@ def is_directive_registered(name: str) -> bool:
return name in directives._directives
-def register_directive(name: str, directive: Type[Directive]) -> None:
+def register_directive(name: str, directive: "Type[Directive]") -> None:
"""Register a directive to docutils.
This modifies global state of docutils. So it is better to use this
@@ -99,12 +100,12 @@ def unregister_role(name: str) -> None:
roles._roles.pop(name, None)
-def is_node_registered(node: Type[Element]) -> bool:
+def is_node_registered(node: "Type[Element]") -> bool:
"""Check the *node* is already registered."""
return hasattr(nodes.GenericNodeVisitor, 'visit_' + node.__name__)
-def register_node(node: Type[Element]) -> None:
+def register_node(node: "Type[Element]") -> None:
"""Register a node to docutils.
This modifies global state of some visitors. So it is better to use this
@@ -115,7 +116,7 @@ def register_node(node: Type[Element]) -> None:
additional_nodes.add(node)
-def unregister_node(node: Type[Element]) -> None:
+def unregister_node(node: "Type[Element]") -> None:
"""Unregister a node from docutils.
This is inverse of ``nodes._add_nodes_class_names()``.
@@ -186,7 +187,7 @@ class sphinx_domains:
def __enter__(self) -> None:
self.enable()
- def __exit__(self, exc_type: Type[Exception], exc_value: Exception, traceback: Any) -> bool: # NOQA
+ def __exit__(self, exc_type: "Type[Exception]", exc_value: Exception, traceback: Any) -> bool: # NOQA
self.disable()
return False
@@ -229,7 +230,7 @@ class sphinx_domains:
raise ElementLookupError
- def lookup_directive(self, directive_name: str, language_module: ModuleType, document: nodes.document) -> Tuple[Optional[Type[Directive]], List[system_message]]: # NOQA
+ def lookup_directive(self, directive_name: str, language_module: ModuleType, document: nodes.document) -> Tuple[Optional["Type[Directive]"], List[system_message]]: # NOQA
try:
return self.lookup_domain_element('directive', directive_name)
except ElementLookupError:
diff --git a/sphinx/util/logging.py b/sphinx/util/logging.py
index d6667dacd..60a409093 100644
--- a/sphinx/util/logging.py
+++ b/sphinx/util/logging.py
@@ -12,7 +12,7 @@ import logging
import logging.handlers
from collections import defaultdict
from contextlib import contextmanager
-from typing import Any, Dict, Generator, IO, List, Tuple, Type, Union
+from typing import Any, Dict, Generator, IO, List, Tuple, Union
from docutils import nodes
from docutils.nodes import Node
@@ -23,6 +23,7 @@ from sphinx.util.console import colorize
if False:
# For type annotation
+ from typing import Type # for python3.5.1
from sphinx.application import Sphinx
diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py
index e0aaaa14e..abbc432df 100644
--- a/sphinx/util/nodes.py
+++ b/sphinx/util/nodes.py
@@ -10,7 +10,7 @@
import re
import warnings
-from typing import Any, Callable, Iterable, List, Set, Tuple, Type
+from typing import Any, Callable, Iterable, List, Set, Tuple
from typing import cast
from docutils import nodes
@@ -26,6 +26,7 @@ from sphinx.util import logging
if False:
# For type annotation
+ from typing import Type # for python3.5.1
from sphinx.builders import Builder
from sphinx.utils.tags import Tags
@@ -59,7 +60,7 @@ class NodeMatcher:
# => [<reference ...>, <reference ...>, ...]
"""
- def __init__(self, *classes: Type[Node], **attrs) -> None:
+ def __init__(self, *classes: "Type[Node]", **attrs) -> None:
self.classes = classes
self.attrs = attrs
diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py
index 3751fcc08..f9c7ce6c4 100644
--- a/sphinx/util/osutil.py
+++ b/sphinx/util/osutil.py
@@ -19,11 +19,15 @@ import time
import warnings
from io import StringIO
from os import path
-from typing import Any, Generator, Iterator, List, Tuple, Type
+from typing import Any, Generator, Iterator, List, Tuple
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
from sphinx.testing.path import path as Path
+if False:
+ # For type annotation
+ from typing import Type # for python3.5.1
+
# Errnos that we need.
EEXIST = getattr(errno, 'EEXIST', 0) # RemovedInSphinx40Warning
ENOENT = getattr(errno, 'ENOENT', 0) # RemovedInSphinx40Warning
@@ -248,7 +252,7 @@ class FileAvoidWrite:
def __enter__(self) -> "FileAvoidWrite":
return self
- def __exit__(self, exc_type: Type[Exception], exc_value: Exception, traceback: Any) -> bool: # NOQA
+ def __exit__(self, exc_type: "Type[Exception]", exc_value: Exception, traceback: Any) -> bool: # NOQA
self.close()
return True