From a073e17537c2aacaac305feadea58d4473ec97f4 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 14 Feb 2018 22:57:20 +0900 Subject: [PATCH] Use typing.TYPE_CHECKING for typehints --- sphinx/addnodes.py | 5 +++-- sphinx/application.py | 4 ++-- sphinx/builders/__init__.py | 4 ++-- sphinx/builders/_epub_base.py | 4 ++-- sphinx/builders/applehelp.py | 4 ++-- sphinx/builders/changes.py | 4 ++-- sphinx/builders/devhelp.py | 4 ++-- sphinx/builders/dummy.py | 4 ++-- sphinx/builders/epub3.py | 4 ++-- sphinx/builders/gettext.py | 4 ++-- sphinx/builders/html.py | 4 ++-- sphinx/builders/htmlhelp.py | 4 ++-- sphinx/builders/latex.py | 4 ++-- sphinx/builders/linkcheck.py | 4 ++-- sphinx/builders/manpage.py | 4 ++-- sphinx/builders/qthelp.py | 4 ++-- sphinx/builders/texinfo.py | 4 ++-- sphinx/builders/text.py | 4 ++-- sphinx/builders/websupport.py | 5 +++-- sphinx/builders/xml.py | 4 ++-- sphinx/cmd/build.py | 4 ++-- sphinx/cmd/quickstart.py | 4 ++-- sphinx/cmdline.py | 4 ++-- sphinx/config.py | 5 ++--- sphinx/directives/__init__.py | 4 ++-- sphinx/directives/code.py | 4 ++-- sphinx/directives/other.py | 5 +++-- sphinx/directives/patches.py | 5 +++-- sphinx/domains/__init__.py | 4 ++-- sphinx/domains/c.py | 4 ++-- sphinx/domains/cpp.py | 4 ++-- sphinx/domains/javascript.py | 5 +++-- sphinx/domains/python.py | 4 ++-- sphinx/domains/rst.py | 4 ++-- sphinx/domains/std.py | 4 ++-- sphinx/environment/__init__.py | 4 ++-- sphinx/environment/adapters/asset.py | 5 +++-- sphinx/environment/adapters/indexentries.py | 4 ++-- sphinx/environment/adapters/toctree.py | 5 +++-- sphinx/environment/collectors/__init__.py | 5 +++-- sphinx/environment/collectors/asset.py | 4 ++-- sphinx/environment/collectors/dependencies.py | 4 ++-- sphinx/environment/collectors/indexentries.py | 5 +++-- sphinx/environment/collectors/metadata.py | 5 +++-- sphinx/environment/collectors/title.py | 5 +++-- sphinx/environment/collectors/toctree.py | 5 +++-- sphinx/errors.py | 5 +++-- sphinx/events.py | 4 ++-- sphinx/ext/apidoc.py | 4 ++-- sphinx/ext/autodoc/__init__.py | 4 ++-- sphinx/ext/autodoc/directive.py | 5 +++-- sphinx/ext/autodoc/importer.py | 4 ++-- sphinx/ext/autodoc/inspector.py | 4 ++-- sphinx/ext/autosectionlabel.py | 4 +++- sphinx/ext/autosummary/__init__.py | 4 ++-- sphinx/ext/autosummary/generate.py | 4 ++-- sphinx/ext/coverage.py | 4 ++-- sphinx/ext/doctest.py | 4 ++-- sphinx/ext/graphviz.py | 4 ++-- sphinx/ext/ifconfig.py | 5 +++-- sphinx/ext/imgconverter.py | 4 ++-- sphinx/ext/imgmath.py | 4 ++-- sphinx/ext/inheritance_diagram.py | 4 ++-- sphinx/ext/intersphinx.py | 4 ++-- sphinx/ext/linkcode.py | 5 +++-- sphinx/ext/mathbase.py | 5 +++-- sphinx/ext/napoleon/__init__.py | 4 ++-- sphinx/ext/napoleon/docstring.py | 4 ++-- sphinx/ext/napoleon/iterators.py | 4 ++-- sphinx/ext/pngmath.py | 4 ++-- sphinx/ext/todo.py | 5 +++-- sphinx/ext/viewcode.py | 4 ++-- sphinx/extension.py | 5 +++-- sphinx/highlighting.py | 5 +++-- sphinx/io.py | 4 ++-- sphinx/jinja2glue.py | 5 ++--- sphinx/locale/__init__.py | 4 ++-- sphinx/make_mode.py | 4 ++-- sphinx/parsers.py | 5 +++-- sphinx/pycode/__init__.py | 5 +++-- sphinx/pycode/parser.py | 4 ++-- sphinx/registry.py | 4 ++-- sphinx/roles.py | 4 ++-- sphinx/search/__init__.py | 4 ++-- sphinx/search/da.py | 2 ++ sphinx/search/de.py | 2 ++ sphinx/search/en.py | 5 +++-- sphinx/search/es.py | 2 ++ sphinx/search/fi.py | 2 ++ sphinx/search/fr.py | 2 ++ sphinx/search/hu.py | 2 ++ sphinx/search/it.py | 2 ++ sphinx/search/ja.py | 4 ++-- sphinx/search/nl.py | 2 ++ sphinx/search/no.py | 2 ++ sphinx/search/pt.py | 2 ++ sphinx/search/ro.py | 5 +++-- sphinx/search/ru.py | 2 ++ sphinx/search/sv.py | 2 ++ sphinx/search/tr.py | 5 +++-- sphinx/search/zh.py | 4 ++-- sphinx/setup_command.py | 4 ++-- sphinx/testing/fixtures.py | 3 ++- sphinx/testing/util.py | 3 ++- sphinx/theming.py | 4 ++-- sphinx/transforms/__init__.py | 4 ++-- sphinx/transforms/compact_bullet_list.py | 5 +++-- sphinx/transforms/i18n.py | 4 ++-- sphinx/transforms/post_transforms/__init__.py | 4 ++-- sphinx/transforms/post_transforms/images.py | 4 ++-- sphinx/util/__init__.py | 4 ++-- sphinx/util/console.py | 5 +++-- sphinx/util/docfields.py | 5 +++-- sphinx/util/docstrings.py | 5 +++-- sphinx/util/docutils.py | 4 ++-- sphinx/util/fileutil.py | 4 ++-- sphinx/util/i18n.py | 6 ++++-- sphinx/util/images.py | 5 ++--- sphinx/util/inspect.py | 4 ++-- sphinx/util/inventory.py | 6 ++++-- sphinx/util/jsdump.py | 5 +++-- sphinx/util/jsonimpl.py | 5 +++-- sphinx/util/logging.py | 4 ++-- sphinx/util/matching.py | 5 +++-- sphinx/util/nodes.py | 4 ++-- sphinx/util/osutil.py | 5 +++-- sphinx/util/parallel.py | 5 +++-- sphinx/util/pycompat.py | 5 +++-- sphinx/util/requests.py | 4 ++-- sphinx/util/rst.py | 4 ++-- sphinx/util/smartypants.py | 3 ++- sphinx/util/tags.py | 6 ++++-- sphinx/util/template.py | 5 +++-- sphinx/versioning.py | 4 ++-- sphinx/writers/html.py | 4 ++-- sphinx/writers/html5.py | 4 ++-- sphinx/writers/latex.py | 4 ++-- sphinx/writers/manpage.py | 5 +++-- sphinx/writers/texinfo.py | 4 ++-- sphinx/writers/text.py | 4 ++-- sphinx/writers/xml.py | 5 +++-- 141 files changed, 327 insertions(+), 257 deletions(-) diff --git a/sphinx/addnodes.py b/sphinx/addnodes.py index e6999bd16a..950b9b8ca5 100644 --- a/sphinx/addnodes.py +++ b/sphinx/addnodes.py @@ -9,10 +9,11 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes -if False: - # For type annotation +if TYPE_CHECKING: from typing import List, Sequence # NOQA diff --git a/sphinx/application.py b/sphinx/application.py index 0305f75607..1495d6eaff 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -18,6 +18,7 @@ import sys import warnings from collections import deque from os import path +from typing import TYPE_CHECKING from docutils import nodes from docutils.parsers.rst import directives, roles @@ -43,8 +44,7 @@ from sphinx.util.i18n import find_catalog_source_files from sphinx.util.osutil import ENOENT, ensuredir from sphinx.util.tags import Tags -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, IO, Iterable, Iterator, List, Tuple, Type, Union # NOQA from docutils.parsers import Parser # NOQA from docutils.transform import Transform # NOQA diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index 5c4714e8f0..2cd418ce37 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -11,6 +11,7 @@ import warnings from os import path +from typing import TYPE_CHECKING from docutils import nodes @@ -32,8 +33,7 @@ try: except ImportError: multiprocessing = None -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, Iterable, List, Sequence, Set, Tuple, Union # NOQA from sphinx.application import Sphinx # NOQA from sphinx.config import Config # NOQA diff --git a/sphinx/builders/_epub_base.py b/sphinx/builders/_epub_base.py index d44e7f2bea..880326100b 100644 --- a/sphinx/builders/_epub_base.py +++ b/sphinx/builders/_epub_base.py @@ -13,6 +13,7 @@ import os import re from collections import namedtuple from os import path +from typing import TYPE_CHECKING from zipfile import ZIP_DEFLATED, ZIP_STORED, ZipFile from docutils import nodes @@ -34,8 +35,7 @@ except ImportError: except ImportError: Image = None -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Tuple # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/builders/applehelp.py b/sphinx/builders/applehelp.py index d7974696ce..d850581a8d 100644 --- a/sphinx/builders/applehelp.py +++ b/sphinx/builders/applehelp.py @@ -16,6 +16,7 @@ import plistlib import shlex import subprocess from os import path, environ +from typing import TYPE_CHECKING from sphinx.builders.html import StandaloneHTMLBuilder from sphinx.config import string_classes @@ -27,8 +28,7 @@ from sphinx.util.matching import Matcher from sphinx.util.osutil import copyfile, ensuredir, make_filename from sphinx.util.pycompat import htmlescape -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/builders/changes.py b/sphinx/builders/changes.py index e8b6650cb2..eb7bb15542 100644 --- a/sphinx/builders/changes.py +++ b/sphinx/builders/changes.py @@ -11,6 +11,7 @@ import codecs from os import path +from typing import TYPE_CHECKING from six import iteritems @@ -24,8 +25,7 @@ from sphinx.util.fileutil import copy_asset_file from sphinx.util.osutil import ensuredir, os_path from sphinx.util.pycompat import htmlescape -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Tuple # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/builders/devhelp.py b/sphinx/builders/devhelp.py index 96e06afdce..13e0beb285 100644 --- a/sphinx/builders/devhelp.py +++ b/sphinx/builders/devhelp.py @@ -15,6 +15,7 @@ from __future__ import absolute_import import gzip import re from os import path +from typing import TYPE_CHECKING from docutils import nodes @@ -29,8 +30,7 @@ try: except ImportError: import lxml.etree as etree # type: ignore -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/builders/dummy.py b/sphinx/builders/dummy.py index 08d99a584f..e0f2a3dab6 100644 --- a/sphinx/builders/dummy.py +++ b/sphinx/builders/dummy.py @@ -9,11 +9,11 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING from sphinx.builders import Builder -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, Set # NOQA from docutils import nodes # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/builders/epub3.py b/sphinx/builders/epub3.py index 0ea0dcf27e..da252b3597 100644 --- a/sphinx/builders/epub3.py +++ b/sphinx/builders/epub3.py @@ -12,6 +12,7 @@ from collections import namedtuple from os import path +from typing import TYPE_CHECKING from sphinx import package_dir from sphinx.builders import _epub_base @@ -21,8 +22,7 @@ from sphinx.util.fileutil import copy_asset_file from sphinx.util.i18n import format_date from sphinx.util.osutil import make_filename -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, Iterable, List # NOQA from docutils import nodes # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/builders/gettext.py b/sphinx/builders/gettext.py index 6f38816df3..a5cca6a47a 100644 --- a/sphinx/builders/gettext.py +++ b/sphinx/builders/gettext.py @@ -16,6 +16,7 @@ from collections import defaultdict from datetime import datetime, tzinfo, timedelta from os import path, walk, getenv from time import time +from typing import TYPE_CHECKING from uuid import uuid4 from six import iteritems, StringIO @@ -29,8 +30,7 @@ from sphinx.util.nodes import extract_messages, traverse_translatable_index from sphinx.util.osutil import safe_relpath, ensuredir, canon_path from sphinx.util.tags import Tags -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, DefaultDict, Dict, Iterable, List, Set, Tuple # NOQA from docutils import nodes # NOQA from sphinx.util.i18n import CatalogInfo # NOQA diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index e2f3909cca..c1bb4dbf2d 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -16,6 +16,7 @@ import sys import warnings from hashlib import md5 from os import path +from typing import TYPE_CHECKING import docutils from docutils import nodes @@ -51,8 +52,7 @@ from sphinx.util.osutil import SEP, os_path, relative_uri, ensuredir, \ movefile, copyfile from sphinx.writers.html import HTMLWriter, HTMLTranslator -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, IO, Iterable, Iterator, List, Type, Tuple, Union # NOQA from sphinx.application import Sphinx # NOQA from sphinx.config import Config # NOQA diff --git a/sphinx/builders/htmlhelp.py b/sphinx/builders/htmlhelp.py index ac32a42dbe..a518582b48 100644 --- a/sphinx/builders/htmlhelp.py +++ b/sphinx/builders/htmlhelp.py @@ -14,6 +14,7 @@ from __future__ import print_function import codecs import os from os import path +from typing import TYPE_CHECKING from docutils import nodes @@ -24,8 +25,7 @@ from sphinx.util import logging from sphinx.util.osutil import make_filename from sphinx.util.pycompat import htmlescape -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, IO, List, Tuple # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/builders/latex.py b/sphinx/builders/latex.py index c66d00d4f8..55d1f99d13 100644 --- a/sphinx/builders/latex.py +++ b/sphinx/builders/latex.py @@ -11,6 +11,7 @@ import os from os import path +from typing import TYPE_CHECKING from docutils import nodes from docutils.frontend import OptionParser @@ -32,8 +33,7 @@ from sphinx.util.nodes import inline_all_toctrees from sphinx.util.osutil import SEP, make_filename from sphinx.writers.latex import LaTeXWriter, LaTeXTranslator -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, Iterable, List, Tuple, Union # NOQA from sphinx.application import Sphinx # NOQA from sphinx.config import Config # NOQA diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py index 8a10a4f2cb..c29c7ab069 100644 --- a/sphinx/builders/linkcheck.py +++ b/sphinx/builders/linkcheck.py @@ -14,6 +14,7 @@ import re import socket import threading from os import path +from typing import TYPE_CHECKING from docutils import nodes from requests.exceptions import HTTPError @@ -37,8 +38,7 @@ from sphinx.util.console import ( # type: ignore ) from sphinx.util.requests import is_ssl_error -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Set, Tuple, Union # NOQA from sphinx.application import Sphinx # NOQA from sphinx.util.requests.requests import Response # NOQA diff --git a/sphinx/builders/manpage.py b/sphinx/builders/manpage.py index 7a691ccf0c..fb7c15ac53 100644 --- a/sphinx/builders/manpage.py +++ b/sphinx/builders/manpage.py @@ -10,6 +10,7 @@ """ from os import path +from typing import TYPE_CHECKING from docutils.frontend import OptionParser from docutils.io import FileOutput @@ -24,8 +25,7 @@ from sphinx.util.nodes import inline_all_toctrees from sphinx.util.osutil import make_filename from sphinx.writers.manpage import ManualPageWriter, ManualPageTranslator -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Set, Union # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/builders/qthelp.py b/sphinx/builders/qthelp.py index 776a2d142b..089470cb60 100644 --- a/sphinx/builders/qthelp.py +++ b/sphinx/builders/qthelp.py @@ -14,6 +14,7 @@ import os import posixpath import re from os import path +from typing import TYPE_CHECKING from docutils import nodes from six import text_type @@ -26,8 +27,7 @@ from sphinx.util import force_decode, logging from sphinx.util.osutil import make_filename from sphinx.util.pycompat import htmlescape -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Tuple # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/builders/texinfo.py b/sphinx/builders/texinfo.py index c9a95a5fc2..282689cef2 100644 --- a/sphinx/builders/texinfo.py +++ b/sphinx/builders/texinfo.py @@ -11,6 +11,7 @@ import os from os import path +from typing import TYPE_CHECKING from docutils import nodes from docutils.frontend import OptionParser @@ -30,8 +31,7 @@ from sphinx.util.nodes import inline_all_toctrees from sphinx.util.osutil import SEP, make_filename from sphinx.writers.texinfo import TexinfoWriter, TexinfoTranslator -if False: - # For type annotation +if TYPE_CHECKING: from sphinx.application import Sphinx # NOQA from typing import Any, Dict, Iterable, List, Tuple, Union # NOQA diff --git a/sphinx/builders/text.py b/sphinx/builders/text.py index babb6cceeb..be33c0f9e3 100644 --- a/sphinx/builders/text.py +++ b/sphinx/builders/text.py @@ -11,6 +11,7 @@ import codecs from os import path +from typing import TYPE_CHECKING from docutils.io import StringOutput @@ -19,8 +20,7 @@ from sphinx.util import logging from sphinx.util.osutil import ensuredir, os_path from sphinx.writers.text import TextWriter, TextTranslator -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, Iterator, Set, Tuple # NOQA from docutils import nodes # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/builders/websupport.py b/sphinx/builders/websupport.py index 1fe9e20014..b7a45c570f 100644 --- a/sphinx/builders/websupport.py +++ b/sphinx/builders/websupport.py @@ -9,8 +9,9 @@ :license: BSD, see LICENSE for details. """ -if False: - # For type annotation +from typing import TYPE_CHECKING + +if TYPE_CHECKING: from typing import Any, Dict # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/builders/xml.py b/sphinx/builders/xml.py index 80d7723aa5..47a9f47d5e 100644 --- a/sphinx/builders/xml.py +++ b/sphinx/builders/xml.py @@ -11,6 +11,7 @@ import codecs from os import path +from typing import TYPE_CHECKING from docutils import nodes from docutils.io import StringOutput @@ -21,8 +22,7 @@ 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 +if TYPE_CHECKING: from typing import Any, Dict, Iterator, Set # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/cmd/build.py b/sphinx/cmd/build.py index c0c31ae679..f01a4f9411 100644 --- a/sphinx/cmd/build.py +++ b/sphinx/cmd/build.py @@ -10,9 +10,9 @@ """ import sys +from typing import TYPE_CHECKING -if False: - # For type annotation +if TYPE_CHECKING: from typing import List # NOQA diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py index 395c33245d..795d140d3a 100644 --- a/sphinx/cmd/quickstart.py +++ b/sphinx/cmd/quickstart.py @@ -19,6 +19,7 @@ import time from collections import OrderedDict from io import open from os import path +from typing import TYPE_CHECKING # try to import readline, unix specific enhancement try: @@ -43,8 +44,7 @@ from sphinx.util.console import ( # type: ignore from sphinx.util.osutil import ensuredir, make_filename from sphinx.util.template import SphinxRenderer -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, List, Pattern, Union # NOQA TERM_ENCODING = getattr(sys.stdin, 'encoding', None) diff --git a/sphinx/cmdline.py b/sphinx/cmdline.py index 908da68d8c..2fa06a1ab5 100644 --- a/sphinx/cmdline.py +++ b/sphinx/cmdline.py @@ -15,6 +15,7 @@ import multiprocessing import sys import traceback from os import path +from typing import TYPE_CHECKING from docutils.utils import SystemMessage from six import text_type, binary_type @@ -28,8 +29,7 @@ from sphinx.util.docutils import docutils_namespace, patch_docutils from sphinx.util.osutil import abspath, fs_encoding from sphinx.util.pycompat import terminal_safe -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, IO, List, Union # NOQA diff --git a/sphinx/config.py b/sphinx/config.py index 1f80ab3669..4f8bf969d1 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -12,7 +12,7 @@ import re import traceback from os import path, getenv -from typing import Any, NamedTuple, Union +from typing import TYPE_CHECKING, Any, NamedTuple, Union from six import PY2, PY3, iteritems, string_types, binary_type, text_type, integer_types @@ -23,8 +23,7 @@ from sphinx.util.i18n import format_date from sphinx.util.osutil import cd from sphinx.util.pycompat import execfile_, NoneType -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, Iterable, Iterator, List, Tuple, Union # NOQA from sphinx.util.tags import Tags # NOQA diff --git a/sphinx/directives/__init__.py b/sphinx/directives/__init__.py index dc51810d3f..d1aa4a6bda 100644 --- a/sphinx/directives/__init__.py +++ b/sphinx/directives/__init__.py @@ -10,6 +10,7 @@ """ import re +from typing import TYPE_CHECKING from docutils import nodes from docutils.parsers.rst import Directive, directives, roles @@ -29,8 +30,7 @@ from sphinx.directives.patches import ( # noqa Figure, Meta ) -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List # NOQA from sphinx.application import Sphinx # NOQA from sphinx.environment import BuildEnvironment # NOQA diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py index ae67cf4c6d..91b8661b4e 100644 --- a/sphinx/directives/code.py +++ b/sphinx/directives/code.py @@ -10,6 +10,7 @@ import codecs import sys from difflib import unified_diff +from typing import TYPE_CHECKING from docutils import nodes from docutils.parsers.rst import Directive, directives @@ -21,8 +22,7 @@ from sphinx.util import logging from sphinx.util import parselinenos from sphinx.util.nodes import set_source_info -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Tuple # NOQA from sphinx.application import Sphinx # NOQA from sphinx.config import Config # NOQA diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py index 4d983185f4..6c1a4cd868 100644 --- a/sphinx/directives/other.py +++ b/sphinx/directives/other.py @@ -7,6 +7,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes from docutils.parsers.rst import Directive, directives from docutils.parsers.rst.directives.admonitions import BaseAdmonition @@ -21,8 +23,7 @@ from sphinx.util.matching import patfilter from sphinx.util.nodes import explicit_title_re, set_source_info, \ process_index_entry -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Tuple # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/directives/patches.py b/sphinx/directives/patches.py index c97340a810..cb8ca31fa2 100644 --- a/sphinx/directives/patches.py +++ b/sphinx/directives/patches.py @@ -7,6 +7,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes from docutils.parsers.rst import directives from docutils.parsers.rst.directives import images, html, tables @@ -14,8 +16,7 @@ from docutils.parsers.rst.directives import images, html, tables from sphinx import addnodes from sphinx.util.nodes import set_source_info -if False: - # For type annotation +if TYPE_CHECKING: from typing import Dict, List # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/domains/__init__.py b/sphinx/domains/__init__.py index c68d374721..3ae957fec6 100644 --- a/sphinx/domains/__init__.py +++ b/sphinx/domains/__init__.py @@ -11,14 +11,14 @@ """ import copy +from typing import TYPE_CHECKING from six import iteritems from sphinx.errors import SphinxError from sphinx.locale import _ -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, Iterable, List, Tuple, Type, Union # NOQA from docutils import nodes # NOQA from docutils.parsers.rst.states import Inliner # NOQA diff --git a/sphinx/domains/c.py b/sphinx/domains/c.py index f0c81db7b8..3f6a578158 100644 --- a/sphinx/domains/c.py +++ b/sphinx/domains/c.py @@ -11,6 +11,7 @@ import re import string +from typing import TYPE_CHECKING from docutils import nodes @@ -22,8 +23,7 @@ from sphinx.roles import XRefRole from sphinx.util.docfields import Field, TypedField from sphinx.util.nodes import make_refnode -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, Iterator, List, Tuple # NOQA from sphinx.application import Sphinx # NOQA from sphinx.builders import Builder # NOQA diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index 625bbe81e2..c7bb82203f 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -11,6 +11,7 @@ import re from copy import deepcopy +from typing import TYPE_CHECKING from docutils import nodes from docutils.parsers.rst import Directive, directives @@ -28,8 +29,7 @@ from sphinx.util.nodes import make_refnode from sphinx.util.pycompat import UnicodeMixin -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, Iterator, List, Match, Pattern, Tuple, Union # NOQA from sphinx.application import Sphinx # NOQA from sphinx.builders import Builder # NOQA diff --git a/sphinx/domains/javascript.py b/sphinx/domains/javascript.py index 734969fc17..037f1048ba 100644 --- a/sphinx/domains/javascript.py +++ b/sphinx/domains/javascript.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes from docutils.parsers.rst import Directive, directives @@ -21,8 +23,7 @@ from sphinx.roles import XRefRole from sphinx.util.docfields import Field, GroupedField, TypedField from sphinx.util.nodes import make_refnode -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, Iterator, List, Tuple # NOQA from docutils import nodes # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index 5456ca13a7..a87c0482e7 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -10,6 +10,7 @@ """ import re +from typing import TYPE_CHECKING from docutils import nodes from docutils.parsers.rst import Directive, directives @@ -24,8 +25,7 @@ from sphinx.util import logging from sphinx.util.docfields import Field, GroupedField, TypedField from sphinx.util.nodes import make_refnode -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, Iterable, Iterator, List, Tuple, Union # NOQA from sphinx.application import Sphinx # NOQA from sphinx.builders import Builder # NOQA diff --git a/sphinx/domains/rst.py b/sphinx/domains/rst.py index c14eb180fb..f356704bf7 100644 --- a/sphinx/domains/rst.py +++ b/sphinx/domains/rst.py @@ -10,6 +10,7 @@ """ import re +from typing import TYPE_CHECKING from six import iteritems @@ -20,8 +21,7 @@ from sphinx.locale import l_, _ from sphinx.roles import XRefRole from sphinx.util.nodes import make_refnode -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, Iterator, List, Tuple # NOQA from docutils import nodes # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index ad56da63d9..78159808d0 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -11,6 +11,7 @@ import re import unicodedata +from typing import TYPE_CHECKING from docutils import nodes from docutils.parsers.rst import Directive, directives @@ -25,8 +26,7 @@ from sphinx.roles import XRefRole from sphinx.util import ws_re, logging, docname_join from sphinx.util.nodes import clean_astext, make_refnode -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, Iterator, List, Tuple, Type, Union # NOQA from sphinx.application import Sphinx # NOQA from sphinx.builders import Builder # NOQA diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py index 5a05ce26f6..b53fec8886 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -18,6 +18,7 @@ import warnings from collections import defaultdict from copy import copy from os import path +from typing import TYPE_CHECKING from docutils.frontend import OptionParser from docutils.utils import Reporter, get_source_line @@ -42,8 +43,7 @@ from sphinx.util.osutil import SEP, ensuredir from sphinx.util.parallel import ParallelTasks, parallel_available, make_chunks from sphinx.util.websupport import is_commentable -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, IO, Iterator, List, Optional, Pattern, Set, Tuple, Type, Union, Generator # NOQA from docutils import nodes # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/environment/adapters/asset.py b/sphinx/environment/adapters/asset.py index 91f2cf8eba..179fbcb127 100644 --- a/sphinx/environment/adapters/asset.py +++ b/sphinx/environment/adapters/asset.py @@ -9,8 +9,9 @@ :license: BSD, see LICENSE for details. """ -if False: - # For type annotation +from typing import TYPE_CHECKING + +if TYPE_CHECKING: from sphinx.environment import BuildEnvironment # NOQA diff --git a/sphinx/environment/adapters/indexentries.py b/sphinx/environment/adapters/indexentries.py index 5ac8ff1d62..db33a76a71 100644 --- a/sphinx/environment/adapters/indexentries.py +++ b/sphinx/environment/adapters/indexentries.py @@ -12,14 +12,14 @@ import bisect import re import unicodedata from itertools import groupby +from typing import TYPE_CHECKING from six import text_type, iteritems from sphinx.locale import _ from sphinx.util import split_into, logging -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, Pattern, List, Tuple # NOQA from sphinx.builders import Builder # NOQA from sphinx.environment import BuildEnvironment # NOQA diff --git a/sphinx/environment/adapters/toctree.py b/sphinx/environment/adapters/toctree.py index af5d85f236..aeba0cc08c 100644 --- a/sphinx/environment/adapters/toctree.py +++ b/sphinx/environment/adapters/toctree.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes from six import iteritems @@ -16,8 +18,7 @@ from sphinx import addnodes from sphinx.util import url_re, logging from sphinx.util.nodes import clean_astext, process_only_nodes -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List # NOQA from sphinx.builders import Builder # NOQA from sphinx.environment import BuildEnvironment # NOQA diff --git a/sphinx/environment/collectors/__init__.py b/sphinx/environment/collectors/__init__.py index 9d9f5347ce..066f8a4901 100644 --- a/sphinx/environment/collectors/__init__.py +++ b/sphinx/environment/collectors/__init__.py @@ -9,10 +9,11 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from six import itervalues -if False: - # For type annotation +if TYPE_CHECKING: from typing import Dict, List, Set # NOQA from docutils import nodes # NOQA from sphinx.sphinx import Sphinx # NOQA diff --git a/sphinx/environment/collectors/asset.py b/sphinx/environment/collectors/asset.py index 2504a7ea46..d33d8f665b 100644 --- a/sphinx/environment/collectors/asset.py +++ b/sphinx/environment/collectors/asset.py @@ -12,6 +12,7 @@ import os from glob import glob from os import path +from typing import TYPE_CHECKING from docutils import nodes from docutils.utils import relative_path @@ -23,8 +24,7 @@ from sphinx.util import logging from sphinx.util.i18n import get_image_filename_for_language, search_image_for_language from sphinx.util.images import guess_mimetype -if False: - # For type annotation +if TYPE_CHECKING: from typing import Dict, List, Set, Tuple # NOQA from docutils import nodes # NOQA from sphinx.sphinx import Sphinx # NOQA diff --git a/sphinx/environment/collectors/dependencies.py b/sphinx/environment/collectors/dependencies.py index de0b7c080d..453db96817 100644 --- a/sphinx/environment/collectors/dependencies.py +++ b/sphinx/environment/collectors/dependencies.py @@ -10,14 +10,14 @@ """ from os import path +from typing import TYPE_CHECKING from docutils.utils import relative_path from sphinx.environment.collectors import EnvironmentCollector from sphinx.util.osutil import getcwd, fs_encoding -if False: - # For type annotation +if TYPE_CHECKING: from typing import Dict, Set # NOQA from docutils import nodes # NOQA from sphinx.sphinx import Sphinx # NOQA diff --git a/sphinx/environment/collectors/indexentries.py b/sphinx/environment/collectors/indexentries.py index dec5dbc758..9555bcc71a 100644 --- a/sphinx/environment/collectors/indexentries.py +++ b/sphinx/environment/collectors/indexentries.py @@ -9,12 +9,13 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from sphinx import addnodes from sphinx.environment.collectors import EnvironmentCollector from sphinx.util import split_index_msg, logging -if False: - # For type annotation +if TYPE_CHECKING: from typing import Dict, Set # NOQA from docutils import nodes # NOQA from sphinx.applicatin import Sphinx # NOQA diff --git a/sphinx/environment/collectors/metadata.py b/sphinx/environment/collectors/metadata.py index 7d54d2fe69..b1f223ff97 100644 --- a/sphinx/environment/collectors/metadata.py +++ b/sphinx/environment/collectors/metadata.py @@ -9,12 +9,13 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes from sphinx.environment.collectors import EnvironmentCollector -if False: - # For type annotation +if TYPE_CHECKING: from typing import Dict, Set # NOQA from docutils import nodes # NOQA from sphinx.sphinx import Sphinx # NOQA diff --git a/sphinx/environment/collectors/title.py b/sphinx/environment/collectors/title.py index eb23b975f8..96bf4db324 100644 --- a/sphinx/environment/collectors/title.py +++ b/sphinx/environment/collectors/title.py @@ -9,13 +9,14 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes from sphinx.environment.collectors import EnvironmentCollector from sphinx.transforms import SphinxContentsFilter -if False: - # For type annotation +if TYPE_CHECKING: from typing import Dict, Set # NOQA from docutils import nodes # NOQA from sphinx.sphinx import Sphinx # NOQA diff --git a/sphinx/environment/collectors/toctree.py b/sphinx/environment/collectors/toctree.py index a7556eadde..e17c1db396 100644 --- a/sphinx/environment/collectors/toctree.py +++ b/sphinx/environment/collectors/toctree.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes from six import iteritems @@ -18,8 +20,7 @@ from sphinx.environment.collectors import EnvironmentCollector from sphinx.transforms import SphinxContentsFilter from sphinx.util import url_re, logging -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Set, Tuple # NOQA from sphinx.application import Sphinx # NOQA from sphinx.builders import Builder # NOQA diff --git a/sphinx/errors.py b/sphinx/errors.py index eef1a157a9..34c0cae335 100644 --- a/sphinx/errors.py +++ b/sphinx/errors.py @@ -10,8 +10,9 @@ :license: BSD, see LICENSE for details. """ -if False: - # For type annotation +from typing import TYPE_CHECKING + +if TYPE_CHECKING: from typing import Any # NOQA diff --git a/sphinx/events.py b/sphinx/events.py index 097f61fc6e..de9def1b98 100644 --- a/sphinx/events.py +++ b/sphinx/events.py @@ -13,14 +13,14 @@ from __future__ import print_function from collections import OrderedDict, defaultdict +from typing import TYPE_CHECKING from six import itervalues from sphinx.errors import ExtensionError from sphinx.locale import __ -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, List # NOQA diff --git a/sphinx/ext/apidoc.py b/sphinx/ext/apidoc.py index 07c399f25f..642bcf087d 100644 --- a/sphinx/ext/apidoc.py +++ b/sphinx/ext/apidoc.py @@ -23,6 +23,7 @@ import os import sys from fnmatch import fnmatch from os import path +from typing import TYPE_CHECKING from six import binary_type @@ -31,8 +32,7 @@ from sphinx.cmd.quickstart import EXTENSIONS from sphinx.util import rst from sphinx.util.osutil import FileAvoidWrite, ensuredir, walk -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, List, Tuple # NOQA # automodule options diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 0f7231f7ad..a02286c285 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -15,6 +15,7 @@ import inspect import re import sys import warnings +from typing import TYPE_CHECKING from docutils.statemachine import ViewList from six import iteritems, itervalues, text_type, class_types, string_types @@ -34,8 +35,7 @@ from sphinx.util.inspect import Signature, isdescriptor, safe_getmembers, \ safe_getattr, object_description, is_builtin_class_method, \ isenumattribute, isclassmethod, isstaticmethod, getdoc -if False: - # For type annotation +if TYPE_CHECKING: from types import ModuleType # NOQA from typing import Any, Callable, Dict, Iterator, List, Sequence, Set, Tuple, Type, Union # NOQA from docutils import nodes # NOQA diff --git a/sphinx/ext/autodoc/directive.py b/sphinx/ext/autodoc/directive.py index 2a7c6b65ae..f050b2ac44 100644 --- a/sphinx/ext/autodoc/directive.py +++ b/sphinx/ext/autodoc/directive.py @@ -7,6 +7,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes from docutils.parsers.rst import Directive from docutils.statemachine import ViewList @@ -17,8 +19,7 @@ from sphinx.util import logging from sphinx.util.docutils import switch_source_input from sphinx.util.nodes import nested_parse_with_titles -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Set, Type # NOQA from docutils.statemachine import State, StateMachine, StringList # NOQA from docutils.utils import Reporter # NOQA diff --git a/sphinx/ext/autodoc/importer.py b/sphinx/ext/autodoc/importer.py index 618b56378c..db33b42155 100644 --- a/sphinx/ext/autodoc/importer.py +++ b/sphinx/ext/autodoc/importer.py @@ -15,14 +15,14 @@ import traceback import warnings from collections import namedtuple from types import FunctionType, MethodType, ModuleType +from typing import TYPE_CHECKING from six import PY2 from sphinx.util import logging from sphinx.util.inspect import isenumclass, safe_getattr -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, Generator, List, Optional # NOQA logger = logging.getLogger(__name__) diff --git a/sphinx/ext/autodoc/inspector.py b/sphinx/ext/autodoc/inspector.py index 6e07c9547d..19f47b2215 100644 --- a/sphinx/ext/autodoc/inspector.py +++ b/sphinx/ext/autodoc/inspector.py @@ -11,14 +11,14 @@ import typing import warnings +from typing import TYPE_CHECKING from six import StringIO, string_types from sphinx.deprecation import RemovedInSphinx20Warning from sphinx.util.inspect import object_description -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, Tuple # NOQA diff --git a/sphinx/ext/autosectionlabel.py b/sphinx/ext/autosectionlabel.py index 6a3ff1422b..c01f5ef4b6 100644 --- a/sphinx/ext/autosectionlabel.py +++ b/sphinx/ext/autosectionlabel.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes from sphinx.util import logging @@ -16,7 +18,7 @@ from sphinx.util.nodes import clean_astext logger = logging.getLogger(__name__) -if False: +if TYPE_CHECKING: # For type annotation from typing import Any, Dict # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index a2aa210fcf..4728281c3c 100644 --- a/sphinx/ext/autosummary/__init__.py +++ b/sphinx/ext/autosummary/__init__.py @@ -59,6 +59,7 @@ import posixpath import re import sys from types import ModuleType +from typing import TYPE_CHECKING from docutils import nodes from docutils.parsers.rst import Directive, directives @@ -75,8 +76,7 @@ from sphinx.ext.autodoc.importer import import_module from sphinx.pycode import ModuleAnalyzer, PycodeError from sphinx.util import import_object, rst, logging -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Tuple, Type, Union # NOQA from docutils.utils import Inliner # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py index 2818ab3c76..4c67831af3 100644 --- a/sphinx/ext/autosummary/generate.py +++ b/sphinx/ext/autosummary/generate.py @@ -25,6 +25,7 @@ import os import pydoc import re import sys +from typing import TYPE_CHECKING from jinja2 import FileSystemLoader, TemplateNotFound from jinja2.sandbox import SandboxedEnvironment @@ -38,8 +39,7 @@ from sphinx.util.inspect import safe_getattr from sphinx.util.osutil import ensuredir from sphinx.util.rst import escape as rst_escape -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, Tuple, List # NOQA from jinja2 import BaseLoader # NOQA from sphinx import addnodes # NOQA diff --git a/sphinx/ext/coverage.py b/sphinx/ext/coverage.py index 6c9acfc7d2..73bd8d68ee 100644 --- a/sphinx/ext/coverage.py +++ b/sphinx/ext/coverage.py @@ -14,6 +14,7 @@ import glob import inspect import re from os import path +from typing import TYPE_CHECKING from six import iteritems from six.moves import cPickle as pickle @@ -23,8 +24,7 @@ from sphinx.builders import Builder from sphinx.util import logging from sphinx.util.inspect import safe_getattr -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, IO, List, Pattern, Set, Tuple # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/ext/doctest.py b/sphinx/ext/doctest.py index 2a889900d4..b5123204d6 100644 --- a/sphinx/ext/doctest.py +++ b/sphinx/ext/doctest.py @@ -17,6 +17,7 @@ import re import sys import time from os import path +from typing import TYPE_CHECKING from docutils import nodes from docutils.parsers.rst import Directive, directives @@ -32,8 +33,7 @@ from sphinx.util.console import bold # type: ignore from sphinx.util.nodes import set_source_info from sphinx.util.osutil import fs_encoding -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, IO, Iterable, List, Optional, Sequence, Set, Tuple # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/ext/graphviz.py b/sphinx/ext/graphviz.py index 2986bf9c14..da3e55b60e 100644 --- a/sphinx/ext/graphviz.py +++ b/sphinx/ext/graphviz.py @@ -16,6 +16,7 @@ import re from hashlib import sha1 from os import path from subprocess import Popen, PIPE +from typing import TYPE_CHECKING from docutils import nodes from docutils.parsers.rst import Directive, directives @@ -29,8 +30,7 @@ from sphinx.util import logging from sphinx.util.i18n import search_image_for_language from sphinx.util.osutil import ensuredir, ENOENT, EPIPE, EINVAL -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Tuple # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/ext/ifconfig.py b/sphinx/ext/ifconfig.py index 16042ac3f8..57527fada8 100644 --- a/sphinx/ext/ifconfig.py +++ b/sphinx/ext/ifconfig.py @@ -20,14 +20,15 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes from docutils.parsers.rst import Directive import sphinx from sphinx.util.nodes import set_source_info -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/ext/imgconverter.py b/sphinx/ext/imgconverter.py index 95f579e366..3c8d499e3d 100644 --- a/sphinx/ext/imgconverter.py +++ b/sphinx/ext/imgconverter.py @@ -9,6 +9,7 @@ :license: BSD, see LICENSE for details. """ import subprocess +from typing import TYPE_CHECKING from sphinx.errors import ExtensionError from sphinx.locale import __ @@ -16,8 +17,7 @@ from sphinx.transforms.post_transforms.images import ImageConverter from sphinx.util import logging from sphinx.util.osutil import ENOENT, EPIPE, EINVAL -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/ext/imgmath.py b/sphinx/ext/imgmath.py index 5f9d7a1e2b..c35ac293ae 100644 --- a/sphinx/ext/imgmath.py +++ b/sphinx/ext/imgmath.py @@ -17,6 +17,7 @@ import tempfile from hashlib import sha1 from os import path from subprocess import Popen, PIPE +from typing import TYPE_CHECKING from docutils import nodes from six import text_type @@ -31,8 +32,7 @@ from sphinx.util.osutil import ensuredir, ENOENT, cd from sphinx.util.png import read_png_depth, write_png_depth from sphinx.util.pycompat import sys_encoding -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Tuple # NOQA from sphinx.application import Sphinx # NOQA from sphinx.builders import Builder # NOQA diff --git a/sphinx/ext/inheritance_diagram.py b/sphinx/ext/inheritance_diagram.py index 6f8256662a..4420dfe057 100644 --- a/sphinx/ext/inheritance_diagram.py +++ b/sphinx/ext/inheritance_diagram.py @@ -40,6 +40,7 @@ import inspect import re import sys from hashlib import md5 +from typing import TYPE_CHECKING from docutils import nodes from docutils.parsers.rst import Directive, directives @@ -52,8 +53,7 @@ from sphinx.ext.graphviz import render_dot_html, render_dot_latex, \ from sphinx.pycode import ModuleAnalyzer from sphinx.util import force_decode -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Tuple, Dict, Optional # NOQA from sphinx.application import Sphinx # NOQA from sphinx.environment import BuildEnvironment # NOQA diff --git a/sphinx/ext/intersphinx.py b/sphinx/ext/intersphinx.py index 5d373c689d..8d84af7d78 100644 --- a/sphinx/ext/intersphinx.py +++ b/sphinx/ext/intersphinx.py @@ -31,6 +31,7 @@ import posixpath import sys import time from os import path +from typing import TYPE_CHECKING from docutils import nodes from docutils.utils import relative_path @@ -43,8 +44,7 @@ from sphinx.locale import _ from sphinx.util import requests, logging from sphinx.util.inventory import InventoryFile -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, IO, List, Tuple, Union # NOQA from sphinx.application import Sphinx # NOQA from sphinx.config import Config # NOQA diff --git a/sphinx/ext/linkcode.py b/sphinx/ext/linkcode.py index af45f32fa4..8467bffd5f 100644 --- a/sphinx/ext/linkcode.py +++ b/sphinx/ext/linkcode.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes import sphinx @@ -16,8 +18,7 @@ from sphinx import addnodes from sphinx.errors import SphinxError from sphinx.locale import _ -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, Set # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/ext/mathbase.py b/sphinx/ext/mathbase.py index 24c10df3c4..15218963f4 100644 --- a/sphinx/ext/mathbase.py +++ b/sphinx/ext/mathbase.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes, utils from docutils.nodes import make_id from docutils.parsers.rst import Directive, directives @@ -20,8 +22,7 @@ from sphinx.roles import XRefRole from sphinx.util import logging from sphinx.util.nodes import make_refnode, set_source_info -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, Iterable, List, Tuple # NOQA from docutils.parsers.rst.states import Inliner # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/ext/napoleon/__init__.py b/sphinx/ext/napoleon/__init__.py index b65f7f2a16..90374692c9 100644 --- a/sphinx/ext/napoleon/__init__.py +++ b/sphinx/ext/napoleon/__init__.py @@ -10,6 +10,7 @@ """ import sys +from typing import TYPE_CHECKING from six import PY2, iteritems @@ -17,8 +18,7 @@ import sphinx from sphinx.application import Sphinx from sphinx.ext.napoleon.docstring import GoogleDocstring, NumpyDocstring -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List # NOQA diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py index b349c761f8..3c38f41416 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -14,6 +14,7 @@ import collections import inspect import re +from typing import TYPE_CHECKING from six import string_types, u from six.moves import range @@ -21,8 +22,7 @@ from six.moves import range from sphinx.ext.napoleon.iterators import modify_iter from sphinx.util.pycompat import UnicodeMixin -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, List, Tuple, Union # NOQA from sphinx.application import Sphinx # NOQA from sphinx.config import Config as SphinxConfig # NOQA diff --git a/sphinx/ext/napoleon/iterators.py b/sphinx/ext/napoleon/iterators.py index b4bba88632..72be60c82a 100644 --- a/sphinx/ext/napoleon/iterators.py +++ b/sphinx/ext/napoleon/iterators.py @@ -12,9 +12,9 @@ """ import collections +from typing import TYPE_CHECKING -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Iterable # NOQA diff --git a/sphinx/ext/pngmath.py b/sphinx/ext/pngmath.py index ebb05e6157..96a3f02f41 100644 --- a/sphinx/ext/pngmath.py +++ b/sphinx/ext/pngmath.py @@ -18,6 +18,7 @@ import tempfile from hashlib import sha1 from os import path from subprocess import Popen, PIPE +from typing import TYPE_CHECKING from docutils import nodes from six import text_type @@ -31,8 +32,7 @@ from sphinx.util.osutil import ensuredir, ENOENT, cd from sphinx.util.png import read_png_depth, write_png_depth from sphinx.util.pycompat import sys_encoding -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, Tuple # NOQA from sphinx.application import Sphinx # NOQA from sphinx.ext.mathbase import math as math_node, displaymath # NOQA diff --git a/sphinx/ext/todo.py b/sphinx/ext/todo.py index fd3d5c0625..19378f6b5c 100644 --- a/sphinx/ext/todo.py +++ b/sphinx/ext/todo.py @@ -12,6 +12,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes from docutils.parsers.rst import Directive from docutils.parsers.rst import directives @@ -24,8 +26,7 @@ from sphinx.util import logging from sphinx.util.nodes import set_source_info from sphinx.util.texescape import tex_escape_map -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, Iterable, List # NOQA from sphinx.application import Sphinx # NOQA from sphinx.environment import BuildEnvironment # NOQA diff --git a/sphinx/ext/viewcode.py b/sphinx/ext/viewcode.py index 9ba76c9c90..54c1c89233 100644 --- a/sphinx/ext/viewcode.py +++ b/sphinx/ext/viewcode.py @@ -10,6 +10,7 @@ """ import traceback +from typing import TYPE_CHECKING from docutils import nodes from six import iteritems, text_type @@ -21,8 +22,7 @@ from sphinx.pycode import ModuleAnalyzer from sphinx.util import get_full_modname, logging, status_iterator from sphinx.util.nodes import make_refnode -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, Iterable, Iterator, Set, Tuple # NOQA from sphinx.application import Sphinx # NOQA from sphinx.environment import BuildEnvironment # NOQA diff --git a/sphinx/extension.py b/sphinx/extension.py index aa1157ec8e..feb23b8997 100644 --- a/sphinx/extension.py +++ b/sphinx/extension.py @@ -9,14 +9,15 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from six import iteritems from sphinx.errors import VersionRequirementError from sphinx.locale import __ from sphinx.util import logging -if False: - # For type annotation +if TYPE_CHECKING: from typing import Dict # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py index ac1d1118e7..a14efd5100 100644 --- a/sphinx/highlighting.py +++ b/sphinx/highlighting.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from pygments import highlight from pygments.filters import ErrorToken from pygments.formatters import HtmlFormatter, LatexFormatter @@ -26,8 +28,7 @@ from sphinx.util import logging from sphinx.util.pycompat import htmlescape from sphinx.util.texescape import tex_hl_escape_map_new -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict # NOQA from pygments.formatter import Formatter # NOQA diff --git a/sphinx/io.py b/sphinx/io.py index 8f1da22bdc..88fee462f2 100644 --- a/sphinx/io.py +++ b/sphinx/io.py @@ -10,6 +10,7 @@ """ import codecs import re +from typing import TYPE_CHECKING from docutils.core import Publisher from docutils.io import FileInput, NullOutput @@ -33,8 +34,7 @@ from sphinx.transforms.i18n import ( from sphinx.util import logging from sphinx.util.docutils import LoggingReporter -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Tuple, Union # NOQA from docutils import nodes # NOQA from docutils.io import Input # NOQA diff --git a/sphinx/jinja2glue.py b/sphinx/jinja2glue.py index cc935d5774..4dac0210a5 100644 --- a/sphinx/jinja2glue.py +++ b/sphinx/jinja2glue.py @@ -11,7 +11,7 @@ from os import path from pprint import pformat -from typing import Any, Callable, Iterator, Tuple # NOQA +from typing import TYPE_CHECKING, Any, Callable, Iterator, Tuple # NOQA from jinja2 import FileSystemLoader, BaseLoader, TemplateNotFound, \ contextfunction @@ -22,8 +22,7 @@ from six import string_types from sphinx.application import TemplateBridge from sphinx.util.osutil import mtimes_of_files -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, List, Iterator, Tuple # NOQA from jinja2.environment import Environment # NOQA from sphinx.builders import Builder # NOQA diff --git a/sphinx/locale/__init__.py b/sphinx/locale/__init__.py index e148f2c120..c97624f727 100644 --- a/sphinx/locale/__init__.py +++ b/sphinx/locale/__init__.py @@ -10,12 +10,12 @@ """ import gettext +from typing import TYPE_CHECKING from six import PY3, text_type from six.moves import UserString -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, Iterator, List, Tuple # NOQA diff --git a/sphinx/make_mode.py b/sphinx/make_mode.py index 78df061077..301baed497 100644 --- a/sphinx/make_mode.py +++ b/sphinx/make_mode.py @@ -20,14 +20,14 @@ import os import subprocess import sys from os import path +from typing import TYPE_CHECKING import sphinx from sphinx import cmdline from sphinx.util.console import color_terminal, nocolor, bold, blue # type: ignore from sphinx.util.osutil import cd, rmtree -if False: - # For type annotation +if TYPE_CHECKING: from typing import List # NOQA proj_name = os.getenv('SPHINXPROJ', '') diff --git a/sphinx/parsers.py b/sphinx/parsers.py index 34822898f6..57344ddb3e 100644 --- a/sphinx/parsers.py +++ b/sphinx/parsers.py @@ -9,14 +9,15 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + import docutils.parsers import docutils.parsers.rst from docutils.parsers.rst import states from docutils.statemachine import StringList from docutils.transforms.universal import SmartQuotes -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Type # NOQA from docutils import nodes # NOQA from docutils.transforms import Transform # NOQA diff --git a/sphinx/pycode/__init__.py b/sphinx/pycode/__init__.py index de951a19f3..04e63b7282 100644 --- a/sphinx/pycode/__init__.py +++ b/sphinx/pycode/__init__.py @@ -10,14 +10,15 @@ """ from __future__ import print_function +from typing import TYPE_CHECKING + from six import iteritems, BytesIO, StringIO from sphinx.errors import PycodeError from sphinx.pycode.parser import Parser from sphinx.util import get_module_source, detect_encoding -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, IO, List, Tuple # NOQA diff --git a/sphinx/pycode/parser.py b/sphinx/pycode/parser.py index f15da664ad..c5d9be3200 100644 --- a/sphinx/pycode/parser.py +++ b/sphinx/pycode/parser.py @@ -15,11 +15,11 @@ import re import tokenize from token import NAME, NEWLINE, INDENT, DEDENT, NUMBER, OP, STRING from tokenize import COMMENT, NL +from typing import TYPE_CHECKING from six import PY2, text_type -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, IO, List, Tuple # NOQA comment_re = re.compile(u'^\\s*#: ?(.*)\r?\n?$') diff --git a/sphinx/registry.py b/sphinx/registry.py index 28da0435e7..3ab3a69a06 100644 --- a/sphinx/registry.py +++ b/sphinx/registry.py @@ -11,6 +11,7 @@ from __future__ import print_function import traceback +from typing import TYPE_CHECKING from pkg_resources import iter_entry_points from six import iteritems, itervalues, string_types @@ -27,8 +28,7 @@ from sphinx.util import logging from sphinx.util.console import bold # type: ignore from sphinx.util.docutils import directive_helper -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, Iterator, List, Type, Union # NOQA from docutils import nodes # NOQA from docutils.io import Input # NOQA diff --git a/sphinx/roles.py b/sphinx/roles.py index 2971c8fc38..a5142e8e9b 100644 --- a/sphinx/roles.py +++ b/sphinx/roles.py @@ -10,6 +10,7 @@ """ import re +from typing import TYPE_CHECKING from docutils import nodes, utils from six import iteritems @@ -21,8 +22,7 @@ from sphinx.util import ws_re from sphinx.util.nodes import split_explicit_title, process_index_entry, \ set_role_source_info -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Tuple, Type # NOQA from docutils.parsers.rst.states import Inliner # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/search/__init__.py b/sphinx/search/__init__.py index fc55a2a459..58d98cdebf 100644 --- a/sphinx/search/__init__.py +++ b/sphinx/search/__init__.py @@ -10,6 +10,7 @@ """ import re from os import path +from typing import TYPE_CHECKING from six import iteritems, itervalues, text_type, string_types from six.moves import cPickle as pickle @@ -21,8 +22,7 @@ from sphinx.util import jsdump, rpartition from sphinx.util.pycompat import htmlescape from sphinx.search.jssplitter import splitter_code -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, IO, Iterable, List, Tuple, Type, Set # NOQA from docutils import nodes # NOQA from sphinx.environment import BuildEnvironment # NOQA diff --git a/sphinx/search/da.py b/sphinx/search/da.py index b3611152a2..2602aea3b6 100644 --- a/sphinx/search/da.py +++ b/sphinx/search/da.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from sphinx.search import SearchLanguage, parse_stop_word import snowballstemmer diff --git a/sphinx/search/de.py b/sphinx/search/de.py index 89cbe3de51..babb5bb9e0 100644 --- a/sphinx/search/de.py +++ b/sphinx/search/de.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from sphinx.search import SearchLanguage, parse_stop_word import snowballstemmer diff --git a/sphinx/search/en.py b/sphinx/search/en.py index fe9b7d8da6..8ba2b852d2 100644 --- a/sphinx/search/en.py +++ b/sphinx/search/en.py @@ -9,11 +9,12 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from sphinx.search import SearchLanguage from sphinx.util.stemmer import get_stemmer -if False: - # For type annotation +if TYPE_CHECKING: from typing import Dict # NOQA english_stopwords = set(u""" diff --git a/sphinx/search/es.py b/sphinx/search/es.py index 2777811d81..4fff081bb2 100644 --- a/sphinx/search/es.py +++ b/sphinx/search/es.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from sphinx.search import SearchLanguage, parse_stop_word import snowballstemmer diff --git a/sphinx/search/fi.py b/sphinx/search/fi.py index ca63b00217..2f334ab24a 100644 --- a/sphinx/search/fi.py +++ b/sphinx/search/fi.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from sphinx.search import SearchLanguage, parse_stop_word import snowballstemmer diff --git a/sphinx/search/fr.py b/sphinx/search/fr.py index 615a47383b..7bd4abd31a 100644 --- a/sphinx/search/fr.py +++ b/sphinx/search/fr.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from sphinx.search import SearchLanguage, parse_stop_word import snowballstemmer diff --git a/sphinx/search/hu.py b/sphinx/search/hu.py index 85d15bac78..a1c4bab2c1 100644 --- a/sphinx/search/hu.py +++ b/sphinx/search/hu.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from sphinx.search import SearchLanguage, parse_stop_word import snowballstemmer diff --git a/sphinx/search/it.py b/sphinx/search/it.py index b613ce33cb..7239fdef4a 100644 --- a/sphinx/search/it.py +++ b/sphinx/search/it.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from sphinx.search import SearchLanguage, parse_stop_word import snowballstemmer diff --git a/sphinx/search/ja.py b/sphinx/search/ja.py index 0cdc14a118..b400590f29 100644 --- a/sphinx/search/ja.py +++ b/sphinx/search/ja.py @@ -20,6 +20,7 @@ import os import re import sys +from typing import TYPE_CHECKING from six import iteritems, PY3 @@ -39,8 +40,7 @@ from sphinx.errors import SphinxError, ExtensionError from sphinx.search import SearchLanguage from sphinx.util import import_object -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List # NOQA diff --git a/sphinx/search/nl.py b/sphinx/search/nl.py index b2ab4e0f0f..5a13af1da3 100644 --- a/sphinx/search/nl.py +++ b/sphinx/search/nl.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from sphinx.search import SearchLanguage, parse_stop_word import snowballstemmer diff --git a/sphinx/search/no.py b/sphinx/search/no.py index 32f7b38c53..0be73a26d0 100644 --- a/sphinx/search/no.py +++ b/sphinx/search/no.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from sphinx.search import SearchLanguage, parse_stop_word import snowballstemmer diff --git a/sphinx/search/pt.py b/sphinx/search/pt.py index ba9f2529b8..2974d0424e 100644 --- a/sphinx/search/pt.py +++ b/sphinx/search/pt.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from sphinx.search import SearchLanguage, parse_stop_word import snowballstemmer diff --git a/sphinx/search/ro.py b/sphinx/search/ro.py index b4beced2d8..0d9bc31ab7 100644 --- a/sphinx/search/ro.py +++ b/sphinx/search/ro.py @@ -9,12 +9,13 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from sphinx.search import SearchLanguage import snowballstemmer -if False: - # For type annotation +if TYPE_CHECKING: from typing import Dict, Set # NOQA js_stemmer = u""" diff --git a/sphinx/search/ru.py b/sphinx/search/ru.py index 8eb6c3dbb2..7df587a250 100644 --- a/sphinx/search/ru.py +++ b/sphinx/search/ru.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from sphinx.search import SearchLanguage, parse_stop_word import snowballstemmer diff --git a/sphinx/search/sv.py b/sphinx/search/sv.py index 64883381ee..c18c85487b 100644 --- a/sphinx/search/sv.py +++ b/sphinx/search/sv.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from sphinx.search import SearchLanguage, parse_stop_word import snowballstemmer diff --git a/sphinx/search/tr.py b/sphinx/search/tr.py index 4ce42dd767..e97779641b 100644 --- a/sphinx/search/tr.py +++ b/sphinx/search/tr.py @@ -9,12 +9,13 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from sphinx.search import SearchLanguage import snowballstemmer -if False: - # For type annotation +if TYPE_CHECKING: from typing import Dict, Set # NOQA js_stemmer = u""" diff --git a/sphinx/search/zh.py b/sphinx/search/zh.py index 2301e11038..1ec2628e90 100644 --- a/sphinx/search/zh.py +++ b/sphinx/search/zh.py @@ -11,6 +11,7 @@ import os import re +from typing import TYPE_CHECKING from sphinx.search import SearchLanguage from sphinx.util.stemmer import get_stemmer @@ -21,8 +22,7 @@ try: except ImportError: JIEBA = False -if False: - # For type annotation +if TYPE_CHECKING: from typing import Dict, List # NOQA english_stopwords = set(u""" diff --git a/sphinx/setup_command.py b/sphinx/setup_command.py index 1f160fec13..30553f827d 100644 --- a/sphinx/setup_command.py +++ b/sphinx/setup_command.py @@ -17,6 +17,7 @@ import os import sys from distutils.cmd import Command from distutils.errors import DistutilsOptionError, DistutilsExecError # type: ignore +from typing import TYPE_CHECKING from six import StringIO, string_types @@ -26,8 +27,7 @@ from sphinx.util.console import nocolor, color_terminal from sphinx.util.docutils import docutils_namespace, patch_docutils from sphinx.util.osutil import abspath -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, List, Tuple # NOQA diff --git a/sphinx/testing/fixtures.py b/sphinx/testing/fixtures.py index be0037b70e..0ef072a46a 100644 --- a/sphinx/testing/fixtures.py +++ b/sphinx/testing/fixtures.py @@ -15,13 +15,14 @@ import subprocess import sys from collections import namedtuple from tempfile import gettempdir +from typing import TYPE_CHECKING import pytest from six import StringIO, string_types from . import util -if False: +if TYPE_CHECKING: from typing import Dict, Union # NOQA diff --git a/sphinx/testing/util.py b/sphinx/testing/util.py index 60544cfa30..a1e564015e 100644 --- a/sphinx/testing/util.py +++ b/sphinx/testing/util.py @@ -12,6 +12,7 @@ import os import re import sys import warnings +from typing import TYPE_CHECKING from xml.etree import ElementTree from docutils import nodes @@ -24,7 +25,7 @@ from sphinx.ext.autodoc import AutoDirective from sphinx.pycode import ModuleAnalyzer from sphinx.testing.path import path -if False: +if TYPE_CHECKING: from typing import List # NOQA diff --git a/sphinx/theming.py b/sphinx/theming.py index 33c4c76be3..bfd7e68ae5 100644 --- a/sphinx/theming.py +++ b/sphinx/theming.py @@ -14,6 +14,7 @@ import shutil import tempfile import warnings from os import path +from typing import TYPE_CHECKING from zipfile import ZipFile import pkg_resources @@ -29,8 +30,7 @@ from sphinx.util.osutil import ensuredir logger = logging.getLogger(__name__) -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, Iterator, List, Tuple # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/transforms/__init__.py b/sphinx/transforms/__init__.py index a2e92223d2..73513598c4 100644 --- a/sphinx/transforms/__init__.py +++ b/sphinx/transforms/__init__.py @@ -10,6 +10,7 @@ """ import re +from typing import TYPE_CHECKING from docutils import nodes from docutils.transforms import Transform, Transformer @@ -25,8 +26,7 @@ from sphinx.util.docutils import new_document from sphinx.util.i18n import format_date from sphinx.util.nodes import apply_source_workaround, is_smartquotable -if False: - # For type annotation +if TYPE_CHECKING: from sphinx.application import Sphinx # NOQA from sphinx.config import Config # NOQA from sphinx.domain.std import StandardDomain # NOQA diff --git a/sphinx/transforms/compact_bullet_list.py b/sphinx/transforms/compact_bullet_list.py index 0121dd12fd..6e4bb09299 100644 --- a/sphinx/transforms/compact_bullet_list.py +++ b/sphinx/transforms/compact_bullet_list.py @@ -9,13 +9,14 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes from sphinx import addnodes from sphinx.transforms import SphinxTransform -if False: - # For type annotation +if TYPE_CHECKING: from typing import List # NOQA diff --git a/sphinx/transforms/i18n.py b/sphinx/transforms/i18n.py index bb85c76bd9..b4b3f83883 100644 --- a/sphinx/transforms/i18n.py +++ b/sphinx/transforms/i18n.py @@ -10,6 +10,7 @@ """ from os import path +from typing import TYPE_CHECKING from docutils import nodes from docutils.io import StringInput @@ -27,8 +28,7 @@ from sphinx.util.nodes import ( ) from sphinx.util.pycompat import indent -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Tuple # NOQA from sphinx.application import Sphinx # NOQA from sphinx.config import Config # NOQA diff --git a/sphinx/transforms/post_transforms/__init__.py b/sphinx/transforms/post_transforms/__init__.py index ea249b41a5..e1f8260a36 100644 --- a/sphinx/transforms/post_transforms/__init__.py +++ b/sphinx/transforms/post_transforms/__init__.py @@ -10,6 +10,7 @@ """ import warnings +from typing import TYPE_CHECKING from docutils import nodes from docutils.utils import get_source_line @@ -22,8 +23,7 @@ from sphinx.transforms import SphinxTransform from sphinx.util import logging from sphinx.util.nodes import process_only_nodes -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Tuple # NOQA from sphinx.application import Sphinx # NOQA from sphinx.domains import Domain # NOQA diff --git a/sphinx/transforms/post_transforms/images.py b/sphinx/transforms/post_transforms/images.py index b8f4b9a5df..c107f832e9 100644 --- a/sphinx/transforms/post_transforms/images.py +++ b/sphinx/transforms/post_transforms/images.py @@ -12,6 +12,7 @@ import os from hashlib import sha1 from math import ceil +from typing import TYPE_CHECKING from docutils import nodes from six import text_type @@ -22,8 +23,7 @@ from sphinx.util import logging, requests from sphinx.util.images import guess_mimetype, get_image_extension, parse_data_uri from sphinx.util.osutil import ensuredir, movefile -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Tuple # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index dda3fb04c4..3cd429b3c4 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -23,6 +23,7 @@ from collections import deque from datetime import datetime from os import path from time import mktime, strptime +from typing import TYPE_CHECKING from docutils.utils import relative_path from six import text_type, binary_type, itervalues @@ -46,8 +47,7 @@ from sphinx.util.nodes import ( # noqa caption_ref_re) from sphinx.util.matching import patfilter # noqa -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, IO, Iterable, Iterator, List, Pattern, Sequence, Set, Tuple, Union # NOQA diff --git a/sphinx/util/console.py b/sphinx/util/console.py index 7663feb1e2..cf9604f099 100644 --- a/sphinx/util/console.py +++ b/sphinx/util/console.py @@ -8,10 +8,12 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import absolute_import import os import re import sys +from typing import TYPE_CHECKING try: # check if colorama is installed to support color on Windows @@ -19,8 +21,7 @@ try: except ImportError: colorama = None -if False: - # For type annotation +if TYPE_CHECKING: from typing import Dict # NOQA diff --git a/sphinx/util/docfields.py b/sphinx/util/docfields.py index 2f952d7cc7..f41adf67f8 100644 --- a/sphinx/util/docfields.py +++ b/sphinx/util/docfields.py @@ -11,12 +11,13 @@ """ from __future__ import absolute_import +from typing import TYPE_CHECKING + from docutils import nodes from sphinx import addnodes -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Tuple # NOQA from sphinx.domains import Domain # NOQA from sphinx.environment import BuildEnvironment # NOQA diff --git a/sphinx/util/docstrings.py b/sphinx/util/docstrings.py index bc4b96a56b..bc0b2d3015 100644 --- a/sphinx/util/docstrings.py +++ b/sphinx/util/docstrings.py @@ -8,11 +8,12 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import absolute_import import sys +from typing import TYPE_CHECKING -if False: - # For type annotation +if TYPE_CHECKING: from typing import List # NOQA diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py index 50483d3f12..0fb544f49d 100644 --- a/sphinx/util/docutils.py +++ b/sphinx/util/docutils.py @@ -15,6 +15,7 @@ import types from contextlib import contextmanager from copy import copy from distutils.version import LooseVersion +from typing import TYPE_CHECKING import docutils from docutils import nodes @@ -30,8 +31,7 @@ from sphinx.util import logging logger = logging.getLogger(__name__) report_re = re.compile('^(.+?:(?:\\d+)?): \\((DEBUG|INFO|WARNING|ERROR|SEVERE)/(\\d+)?\\) ') -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Generator, Iterator, List, Tuple # NOQA from docutils.statemachine import State, ViewList # NOQA from sphinx.environment import BuildEnvironment # NOQA diff --git a/sphinx/util/fileutil.py b/sphinx/util/fileutil.py index 7caf40275a..9b97258107 100644 --- a/sphinx/util/fileutil.py +++ b/sphinx/util/fileutil.py @@ -13,13 +13,13 @@ from __future__ import absolute_import import codecs import os import posixpath +from typing import TYPE_CHECKING from docutils.utils import relative_path from sphinx.util.osutil import copyfile, ensuredir, walk -if False: - # For type annotation +if TYPE_CHECKING: 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 4989de1c95..c11f593817 100644 --- a/sphinx/util/i18n.py +++ b/sphinx/util/i18n.py @@ -8,6 +8,8 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import absolute_import + import gettext import io import os @@ -15,6 +17,7 @@ import re from collections import namedtuple from datetime import datetime from os import path +from typing import TYPE_CHECKING import babel.dates from babel.messages.mofile import write_mo @@ -26,8 +29,7 @@ from sphinx.util.osutil import SEP, walk logger = logging.getLogger(__name__) -if False: - # For type annotation +if TYPE_CHECKING: from typing import Callable, List, Set # NOQA from sphinx.environment import BuildEnvironment # NOQA diff --git a/sphinx/util/images.py b/sphinx/util/images.py index dd2f2a9e2a..2f43954822 100644 --- a/sphinx/util/images.py +++ b/sphinx/util/images.py @@ -14,7 +14,7 @@ import base64 import imghdr from collections import OrderedDict from os import path -from typing import NamedTuple +from typing import TYPE_CHECKING, NamedTuple import imagesize from six import PY3, BytesIO, iteritems @@ -27,8 +27,7 @@ except ImportError: except ImportError: Image = None -if False: - # For type annotation +if TYPE_CHECKING: from typing import Dict, IO, List, Tuple # NOQA if PY3: diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 6fd5c789c1..dd27859a0e 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -15,14 +15,14 @@ import re import sys import typing from collections import OrderedDict +from typing import TYPE_CHECKING from six import PY2, PY3, StringIO, binary_type, string_types, itervalues from six.moves import builtins from sphinx.util import force_decode -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, List, Tuple, Type # NOQA memory_address_re = re.compile(r' at 0x[0-9a-f]{8,16}(?=>)', re.IGNORECASE) diff --git a/sphinx/util/inventory.py b/sphinx/util/inventory.py index ed4e55bc23..4ed12e2da8 100644 --- a/sphinx/util/inventory.py +++ b/sphinx/util/inventory.py @@ -8,16 +8,18 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import absolute_import + import os import re import zlib +from typing import TYPE_CHECKING from six import PY3 from sphinx.util import logging -if False: - # For type annotation +if TYPE_CHECKING: from typing import Callable, Dict, IO, Iterator, Tuple # NOQA from sphinx.builders import Builder # NOQA from sphinx.environment import BuildEnvironment # NOQA diff --git a/sphinx/util/jsdump.py b/sphinx/util/jsdump.py index 6776691cf8..2226475f6d 100644 --- a/sphinx/util/jsdump.py +++ b/sphinx/util/jsdump.py @@ -9,15 +9,16 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import absolute_import import re +from typing import TYPE_CHECKING from six import iteritems, integer_types, string_types from sphinx.util.pycompat import u -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, IO, List, Match, Union # NOQA _str_re = re.compile(r'"(\\\\|\\"|[^"])*"') diff --git a/sphinx/util/jsonimpl.py b/sphinx/util/jsonimpl.py index fbaa72978a..29e6a1a88d 100644 --- a/sphinx/util/jsonimpl.py +++ b/sphinx/util/jsonimpl.py @@ -8,14 +8,15 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import absolute_import import json +from typing import TYPE_CHECKING from six import text_type from six.moves import UserString -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, IO # NOQA diff --git a/sphinx/util/logging.py b/sphinx/util/logging.py index 09db0028f1..6b0afd6336 100644 --- a/sphinx/util/logging.py +++ b/sphinx/util/logging.py @@ -14,6 +14,7 @@ import logging import logging.handlers from collections import defaultdict from contextlib import contextmanager +from typing import TYPE_CHECKING from docutils import nodes from docutils.utils import get_source_line @@ -22,8 +23,7 @@ from six import PY2, StringIO from sphinx.errors import SphinxWarning from sphinx.util.console import colorize -if False: - # For type annotation +if TYPE_CHECKING: 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 bddf84f5c9..08fb1680ef 100644 --- a/sphinx/util/matching.py +++ b/sphinx/util/matching.py @@ -8,11 +8,12 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import absolute_import import re +from typing import TYPE_CHECKING -if False: - # For type annotation +if TYPE_CHECKING: from typing import Callable, Dict, List, Match, Pattern # NOQA diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py index f439c515e9..9b1e81490e 100644 --- a/sphinx/util/nodes.py +++ b/sphinx/util/nodes.py @@ -11,6 +11,7 @@ from __future__ import absolute_import import re +from typing import TYPE_CHECKING from docutils import nodes from six import text_type @@ -19,8 +20,7 @@ from sphinx import addnodes from sphinx.locale import pairindextypes from sphinx.util import logging -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Iterable, List, Set, Tuple, Union # NOQA from sphinx.builders import Builder # NOQA from sphinx.utils.tags import Tags # NOQA diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index af87caf9ab..ce68fb8b39 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -8,6 +8,7 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import absolute_import from __future__ import print_function import contextlib @@ -21,11 +22,11 @@ import sys import time from io import BytesIO, StringIO from os import path +from typing import TYPE_CHECKING from six import PY2, PY3, text_type -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Iterator, List, Tuple, Union # NOQA # Errnos that we need. diff --git a/sphinx/util/parallel.py b/sphinx/util/parallel.py index fe25773082..be83a40ac7 100644 --- a/sphinx/util/parallel.py +++ b/sphinx/util/parallel.py @@ -8,11 +8,13 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import absolute_import import os import time import traceback from math import sqrt +from typing import TYPE_CHECKING from six import iteritems @@ -24,8 +26,7 @@ except ImportError: from sphinx.errors import SphinxParallelError from sphinx.util import logging -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, List, Sequence # NOQA logger = logging.getLogger(__name__) diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py index 8bcf7e4f80..f1d044a731 100644 --- a/sphinx/util/pycompat.py +++ b/sphinx/util/pycompat.py @@ -8,14 +8,15 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import absolute_import import codecs import sys +from typing import TYPE_CHECKING from six import PY3, text_type, exec_ -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Generator # NOQA diff --git a/sphinx/util/requests.py b/sphinx/util/requests.py index b6c0d1ab82..2eab6e3ec0 100644 --- a/sphinx/util/requests.py +++ b/sphinx/util/requests.py @@ -13,6 +13,7 @@ from __future__ import absolute_import import warnings from contextlib import contextmanager +from typing import TYPE_CHECKING import pkg_resources import requests @@ -75,8 +76,7 @@ else: 'install requests-2.4.1+.' ) -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Generator, Union # NOQA from sphinx.config import Config # NOQA diff --git a/sphinx/util/rst.py b/sphinx/util/rst.py index a406e00445..e2e68f6d0f 100644 --- a/sphinx/util/rst.py +++ b/sphinx/util/rst.py @@ -12,6 +12,7 @@ from __future__ import absolute_import import re from contextlib import contextmanager +from typing import TYPE_CHECKING from docutils.parsers.rst import roles from docutils.parsers.rst.languages import en as english @@ -19,8 +20,7 @@ from docutils.utils import Reporter from sphinx.util import logging -if False: - # For type annotation +if TYPE_CHECKING: from typing import Generator # NOQA symbols_re = re.compile(r'([!--/:-@\[-`{-~])') # symbols without dot(0x2e) diff --git a/sphinx/util/smartypants.py b/sphinx/util/smartypants.py index bca901b18f..97b4e243ea 100644 --- a/sphinx/util/smartypants.py +++ b/sphinx/util/smartypants.py @@ -28,12 +28,13 @@ from __future__ import absolute_import, unicode_literals import re +from typing import TYPE_CHECKING from docutils.utils import smartquotes from sphinx.util.docutils import __version_info__ as docutils_version -if False: # For type annotation +if TYPE_CHECKING: from typing import Iterable, Iterator, Tuple # NOQA diff --git a/sphinx/util/tags.py b/sphinx/util/tags.py index 43a351f65c..b31b422708 100644 --- a/sphinx/util/tags.py +++ b/sphinx/util/tags.py @@ -6,6 +6,9 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import absolute_import + +from typing import TYPE_CHECKING # (ab)use the Jinja parser for parsing our boolean expressions from jinja2 import nodes @@ -14,8 +17,7 @@ from jinja2.parser import Parser env = Environment() -if False: - # For type annotation +if TYPE_CHECKING: from typing import Iterator, List # NOQA diff --git a/sphinx/util/template.py b/sphinx/util/template.py index 5a415d329c..90354e6f25 100644 --- a/sphinx/util/template.py +++ b/sphinx/util/template.py @@ -8,8 +8,10 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import absolute_import import os +from typing import TYPE_CHECKING from jinja2.sandbox import SandboxedEnvironment @@ -17,8 +19,7 @@ from sphinx import package_dir from sphinx.jinja2glue import SphinxFileSystemLoader from sphinx.locale import get_translator -if False: - # For type annotation +if TYPE_CHECKING: from typing import Dict # NOQA from jinja2.loaders import BaseLoader # NOQA diff --git a/sphinx/versioning.py b/sphinx/versioning.py index bd09287758..f50f6cb4cd 100644 --- a/sphinx/versioning.py +++ b/sphinx/versioning.py @@ -11,6 +11,7 @@ """ from itertools import product from operator import itemgetter +from typing import TYPE_CHECKING from uuid import uuid4 from six import iteritems @@ -19,8 +20,7 @@ from six.moves import range, zip_longest from sphinx.transforms import SphinxTransform -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Iterator # NOQA from docutils import nodes # NOQA diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py index 0fc4a7beac..d9bc1e5dd0 100644 --- a/sphinx/writers/html.py +++ b/sphinx/writers/html.py @@ -13,6 +13,7 @@ import copy import os import posixpath import sys +from typing import TYPE_CHECKING from docutils import nodes from docutils.writers.html4css1 import Writer, HTMLTranslator as BaseTranslator @@ -23,8 +24,7 @@ from sphinx.locale import admonitionlabels, _ from sphinx.util import logging from sphinx.util.images import get_image_size -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any # NOQA from sphinx.builders.html import StandaloneHTMLBuilder # NOQA diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py index 21d7626ef1..4a265594ed 100644 --- a/sphinx/writers/html5.py +++ b/sphinx/writers/html5.py @@ -12,6 +12,7 @@ import os import posixpath import sys +from typing import TYPE_CHECKING from docutils import nodes from docutils.writers.html5_polyglot import HTMLTranslator as BaseTranslator @@ -22,8 +23,7 @@ from sphinx.locale import admonitionlabels, _ from sphinx.util import logging from sphinx.util.images import get_image_size -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any # NOQA from sphinx.builders.html import StandaloneHTMLBuilder # NOQA diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index d84bb81a0c..46f4da951c 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -16,6 +16,7 @@ import re import sys from collections import defaultdict from os import path +from typing import TYPE_CHECKING from docutils import nodes, writers from docutils.writers.latex2e import Babel @@ -32,8 +33,7 @@ from sphinx.util.nodes import clean_astext, traverse_parent from sphinx.util.template import LaTeXRenderer from sphinx.util.texescape import tex_escape_map, tex_replace_map -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, Iterator, List, Pattern, Tuple, Set, Union # NOQA from sphinx.builder import Builder # NOQA diff --git a/sphinx/writers/manpage.py b/sphinx/writers/manpage.py index 38954ca818..f647a7cf95 100644 --- a/sphinx/writers/manpage.py +++ b/sphinx/writers/manpage.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes from docutils.writers.manpage import ( MACRO_DEF, @@ -22,8 +24,7 @@ from sphinx.locale import admonitionlabels, _ from sphinx.util import logging from sphinx.util.i18n import format_date -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any # NOQA from sphinx.builders import Builder # NOQA diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py index cce2694793..3767ba3fcf 100644 --- a/sphinx/writers/texinfo.py +++ b/sphinx/writers/texinfo.py @@ -12,6 +12,7 @@ import re import textwrap from os import path +from typing import TYPE_CHECKING from docutils import nodes, writers from six import itervalues @@ -24,8 +25,7 @@ from sphinx.util import logging from sphinx.util.i18n import format_date from sphinx.writers.latex import collected_footnote -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, Iterator, List, Pattern, Set, Tuple, Union # NOQA from sphinx.builders.texinfo import TexinfoBuilder # NOQA diff --git a/sphinx/writers/text.py b/sphinx/writers/text.py index 5e870efa25..12103042fc 100644 --- a/sphinx/writers/text.py +++ b/sphinx/writers/text.py @@ -12,6 +12,7 @@ import os import re import textwrap from itertools import groupby +from typing import TYPE_CHECKING from docutils import nodes, writers from docutils.utils import column_width @@ -21,8 +22,7 @@ from sphinx import addnodes from sphinx.locale import admonitionlabels, _ from sphinx.util import logging -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, List, Tuple, Union # NOQA from sphinx.builders.text import TextBuilder # NOQA diff --git a/sphinx/writers/xml.py b/sphinx/writers/xml.py index f94fe847c6..b40d05ab7a 100644 --- a/sphinx/writers/xml.py +++ b/sphinx/writers/xml.py @@ -9,11 +9,12 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import writers from docutils.writers.docutils_xml import Writer as BaseXMLWriter -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Tuple # NOQA from sphinx.builders import Builder # NOQA