diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 000000000..aa7a96c27 --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,6 @@ +coverage: + status: + patch: + default: + # allowed to drop X% and still result in a "success" commit status + threshold: 0.05 diff --git a/CHANGES b/CHANGES index c1a325bb5..5aad328b6 100644 --- a/CHANGES +++ b/CHANGES @@ -60,6 +60,13 @@ Features added Bugs fixed ---------- +* #4608: epub: Invalid meta tag is generated +* #4260: autodoc: keyword only argument separator is not disappeared if it is + appeared at top of the argument list +* #4622: epub: :confval:`epub_scheme` does not effect to content.opf +* #4627: graphviz: Fit graphviz images to page +* #4617: quickstart: PROJECT_DIR argument is required + Testing -------- diff --git a/sphinx/__init__.py b/sphinx/__init__.py index 1ae4b3cd0..d14a596ad 100644 --- a/sphinx/__init__.py +++ b/sphinx/__init__.py @@ -18,7 +18,6 @@ import os import warnings from os import path -from .cmd import build from .deprecation import RemovedInNextVersionWarning from .deprecation import RemovedInSphinx20Warning @@ -72,6 +71,7 @@ if __version__.endswith('+'): def main(*args, **kwargs): # type: (Any, Any) -> int + from .cmd import build warnings.warn( '`sphinx.main()` has moved to `sphinx.cmd.build.main()`.', RemovedInSphinx20Warning, @@ -81,6 +81,7 @@ def main(*args, **kwargs): if __name__ == '__main__': + from .cmd import build warnings.warn( '`sphinx` has moved to `sphinx.build`.', RemovedInSphinx20Warning, diff --git a/sphinx/addnodes.py b/sphinx/addnodes.py index e6999bd16..950b9b8ca 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 441bc13f9..a3050131c 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -19,6 +19,7 @@ import warnings from collections import deque from inspect import isclass from os import path +from typing import TYPE_CHECKING from docutils import nodes from docutils.parsers.rst import Directive, directives, roles @@ -45,8 +46,7 @@ from sphinx.util.i18n import find_catalog_source_files from sphinx.util.osutil import abspath, 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 @@ -136,9 +136,9 @@ class Sphinx(object): self.html_themes = {} # type: Dict[unicode, unicode] # validate provided directories - self.srcdir = abspath(srcdir) - self.outdir = abspath(outdir) - self.doctreedir = abspath(doctreedir) + self.srcdir = abspath(srcdir) # type: unicode + self.outdir = abspath(outdir) # type: unicode + self.doctreedir = abspath(doctreedir) # type: unicode self.confdir = confdir if self.confdir: # confdir is optional self.confdir = abspath(self.confdir) diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index 07f7b8c9f..bef6f4872 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 d44e7f2be..880326100 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 d7974696c..d850581a8 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 e8b6650cb..eb7bb1554 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 2559ba778..4e204eabb 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 08d99a584..e0f2a3dab 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 0fbfea570..715c6e6c2 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 @@ -144,6 +144,7 @@ class Epub3Builder(_epub_base.EpubBuilder): self.globalcontext['theme_writing_mode'] = THEME_WRITING_MODES.get(writing_mode) self.globalcontext['html_tag'] = self.html_tag self.globalcontext['use_meta_charset'] = self.use_meta_charset + self.globalcontext['skip_ua_compatible'] = True def build_navlist(self, navnodes): # type: (List[nodes.Node]) -> List[NavPoint] diff --git a/sphinx/builders/gettext.py b/sphinx/builders/gettext.py index ec7f23594..21ab8377c 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 0e39ef906..86dc23540 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 @@ -600,9 +600,9 @@ class StandaloneHTMLBuilder(Builder): doctree.settings = self.docsettings self.secnumbers = self.env.toc_secnumbers.get(docname, {}) - self.fignumbers = self.env.toc_fignumbers.get(docname, {}) + self.fignumbers = self.env.toc_fignumbers.get(docname, {}) # type: Dict[unicode, Dict[unicode, Tuple[int, ...]]] # NOQA self.imgpath = relative_uri(self.get_target_uri(docname), '_images') - self.dlpath = relative_uri(self.get_target_uri(docname), '_downloads') + self.dlpath = relative_uri(self.get_target_uri(docname), '_downloads') # type: unicode self.current_docname = docname self.docwriter.write(doctree, destination) self.docwriter.assemble_parts() diff --git a/sphinx/builders/htmlhelp.py b/sphinx/builders/htmlhelp.py index ac32a42db..a518582b4 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 912c40b44..7d6a9621d 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 d35f4159c..24bf13edc 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 7a691ccf0..fb7c15ac5 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 776a2d142..089470cb6 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 c9a95a5fc..282689cef 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 babb6ccee..be33c0f9e 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 1fe9e2001..b7a45c570 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 80d7723aa..47a9f47d5 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 c0c31ae67..f01a4f941 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 395c33245..6a53b40f2 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) @@ -533,7 +533,7 @@ Makefile to be used with sphinx-build. parser.add_argument('--version', action='version', dest='show_version', version='%%(prog)s %s' % __display_version__) - parser.add_argument('path', metavar='PROJECT_DIR', default='.', + parser.add_argument('path', metavar='PROJECT_DIR', default='.', nargs='?', help='output path') group = parser.add_argument_group('Structure options') diff --git a/sphinx/cmdline.py b/sphinx/cmdline.py index 848dbc789..51e0318e7 100644 --- a/sphinx/cmdline.py +++ b/sphinx/cmdline.py @@ -15,6 +15,7 @@ import multiprocessing import os import sys import traceback +from typing import TYPE_CHECKING from docutils.utils import SystemMessage from six import text_type, binary_type @@ -27,8 +28,7 @@ from sphinx.util.console import red, nocolor, color_terminal # type: ignore from sphinx.util.docutils import docutils_namespace, patch_docutils 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 83a8a6371..46e57fd6b 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -13,7 +13,7 @@ import re import traceback from collections import OrderedDict 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 @@ -24,8 +24,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.application import Sphinx # NOQA from sphinx.util.tags import Tags # NOQA diff --git a/sphinx/directives/__init__.py b/sphinx/directives/__init__.py index dc51810d3..d1aa4a6bd 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 b8d7863ad..51abc252b 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 4d983185f..6c1a4cd86 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 14f0ca17e..8407c9981 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, Tuple # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/domains/__init__.py b/sphinx/domains/__init__.py index 009d3bfdb..bcb67d337 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 ca55b6960..c06651eb4 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 c5ce0aa37..7d081ff86 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 8c1e48fbb..ac68a295b 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 a173c8108..fb864a7a0 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 fc533145c..3c053a9d1 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 ee38c4396..0a4c5d5ed 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 1dabae52a..1d2b9f844 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 @@ -165,8 +165,8 @@ class BuildEnvironment(object): # type: (Sphinx) -> None self.app = app self.doctreedir = app.doctreedir - self.srcdir = app.srcdir - self.config = app.config + self.srcdir = app.srcdir # type: unicode + self.config = app.config # type: Config # the method of doctree versioning; see set_versioning_method self.versioning_condition = None # type: Union[bool, Callable] @@ -183,7 +183,7 @@ class BuildEnvironment(object): self._warnfunc = None # type: Callable # this is to invalidate old pickles - self.version = app.registry.get_envversion(app) + self.version = app.registry.get_envversion(app) # type: Dict[unicode, unicode] # All "docnames" here are /-separated and relative and exclude # the source suffix. @@ -248,8 +248,8 @@ class BuildEnvironment(object): # lineno, module, descname, content) # these map absolute path -> (docnames, unique filename) - self.images = FilenameUniqDict() - self.dlfiles = FilenameUniqDict() + self.images = FilenameUniqDict() # type: FilenameUniqDict + self.dlfiles = FilenameUniqDict() # type: FilenameUniqDict # the original URI for images self.original_image_uri = {} # type: Dict[unicode, unicode] diff --git a/sphinx/environment/adapters/asset.py b/sphinx/environment/adapters/asset.py index 91f2cf8eb..179fbcb12 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 5ac8ff1d6..db33a76a7 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 af5d85f23..aeba0cc08 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 9d9f5347c..066f8a490 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 2504a7ea4..d33d8f665 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 de0b7c080..453db9681 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 dec5dbc75..9555bcc71 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 7d54d2fe6..b1f223ff9 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 eb23b975f..96bf4db32 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 b4c5822f0..27fca5540 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 7652e93cb..7ac0d9c85 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 fb62d1776..9d74e778f 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 22974c638..8a93271c1 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 0c23b57fb..a37a76167 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,13 +35,13 @@ 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 from docutils.utils import Reporter # NOQA from sphinx.application import Sphinx # NOQA + from sphinx.environment import BuildEnvironment # NOQA from sphinx.ext.autodoc.directive import DocumenterBridge # NOQA logger = logging.getLogger(__name__) @@ -281,7 +282,7 @@ class Documenter(object): def __init__(self, directive, name, indent=u''): # type: (DocumenterBridge, unicode, unicode) -> None self.directive = directive - self.env = directive.env + self.env = directive.env # type: BuildEnvironment self.options = directive.genopt self.name = name self.indent = indent @@ -745,7 +746,7 @@ class Documenter(object): # where the attribute documentation would actually be found in. # This is used for situations where you have a module that collects the # functions and classes of internal submodules. - self.real_modname = real_modname or self.get_real_modname() + self.real_modname = real_modname or self.get_real_modname() # type: str # try to also get a source code analyzer for attribute docs try: diff --git a/sphinx/ext/autodoc/directive.py b/sphinx/ext/autodoc/directive.py index 2a7c6b65a..f050b2ac4 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 2a2729dca..a83b6b138 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 6e07c9547..19f47b221 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 c447333f5..7a10b3e8d 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 @@ -22,7 +24,7 @@ if False: 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 df06a659c..dcd0a4ef7 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 6a7ff016e..9946ab037 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 6c9acfc7d..73bd8d68e 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 2a889900d..b5123204d 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 08707b733..a061ae885 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 16042ac3f..57527fada 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 8546593a7..45aef39fa 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 5f9d7a1e2..c35ac293a 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 6f8256662..4420dfe05 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 ed972a4be..138c2044c 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 af45f32fa..8467bffd5 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 50a1c67d4..b742469ef 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 docutils.writers.html4css1 import Writer # NOQA diff --git a/sphinx/ext/napoleon/__init__.py b/sphinx/ext/napoleon/__init__.py index 8198a8bf5..28e48d13a 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 530cec203..d632748ec 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -15,6 +15,7 @@ import collections import inspect import re from functools import partial +from typing import TYPE_CHECKING from six import string_types, u from six.moves import range @@ -22,8 +23,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 b4bba8863..72be60c82 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 ebb05e615..96a3f02f4 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 f9977421d..c9a94b358 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 2a152b2af..673cdf8e8 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 732ea327c..7acec4588 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 Any, Dict # NOQA from sphinx.application import Sphinx # NOQA from sphinx.config import Config # NOQA diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py index ac1d1118e..a14efd510 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 86672f316..f37220f8e 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 @@ -305,7 +305,7 @@ def read_doc(app, env, filename): source_class=SphinxDummySourceClass, destination=NullOutput()) pub.set_components(None, 'restructuredtext', None) - pub.process_programmatic_settings(None, env.settings, None) + pub.process_programmatic_settings(None, env.settings, None) # type: ignore pub.set_source(source, filename) pub.publish() return pub.document diff --git a/sphinx/jinja2glue.py b/sphinx/jinja2glue.py index 24dd0e0fd..0cf95d882 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, Union # 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 e148f2c12..c97624f72 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 78df06107..301baed49 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 3a009321e..d34dcae93 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 04353e805..096845eba 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 8f6615b54..f21d1b77d 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 632a1e7e8..77304ed04 100644 --- a/sphinx/registry.py +++ b/sphinx/registry.py @@ -12,6 +12,7 @@ from __future__ import print_function import traceback import warnings +from typing import TYPE_CHECKING from pkg_resources import iter_entry_points from six import iteritems, itervalues @@ -28,8 +29,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 2971c8fc3..a5142e8e9 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 fc55a2a45..58d98cdeb 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 26ac428fe..aac6c4130 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 00e36354b..87c4cf617 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 fe9b7d8da..8ba2b852d 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 971d0c149..972ec1495 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 b2b47781e..b089bef3a 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 9976c1ca7..0f2b68a69 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 9cdee61fe..d3bcf2974 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 db86e386e..64d7c7538 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 0cdc14a11..b400590f2 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 49003d2d1..32fb86937 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 7f5a73858..d1f849228 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 44c7e2118..dc43c0330 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 b4beced2d..0d9bc31ab 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 b628b9866..75870b08f 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 953ae94b5..555b4b641 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 4ce42dd76..e97779641 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 2301e1103..1ec2628e9 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 37fc2d042..af31b923e 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/templates/epub3/content.opf_t b/sphinx/templates/epub3/content.opf_t index faabc86df..c201e49d6 100644 --- a/sphinx/templates/epub3/content.opf_t +++ b/sphinx/templates/epub3/content.opf_t @@ -11,7 +11,7 @@ {{ contributor }} {{ publisher }} {{ copyright }} - {{ id }} + {{ id }} {{ date }} {{ date }} {{ version }} diff --git a/sphinx/testing/fixtures.py b/sphinx/testing/fixtures.py index 76ed154fd..b4b4adf1e 100644 --- a/sphinx/testing/fixtures.py +++ b/sphinx/testing/fixtures.py @@ -15,14 +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: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, Union # NOQA diff --git a/sphinx/testing/util.py b/sphinx/testing/util.py index 1c1e7026d..6fbcd26d9 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,8 +25,7 @@ from sphinx.ext.autodoc import AutoDirective from sphinx.pycode import ModuleAnalyzer from sphinx.testing.path import path -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, Generator, IO, List, Pattern # NOQA diff --git a/sphinx/themes/basic/layout.html b/sphinx/themes/basic/layout.html index fe8829b77..68c7d9e51 100644 --- a/sphinx/themes/basic/layout.html +++ b/sphinx/themes/basic/layout.html @@ -111,8 +111,8 @@ {%- endif %} - {%- if not html5_doctype %} - + {%- if not html5_doctype and not skip_ua_compatible %} + {%- endif %} {%- if use_meta_charset or html5_doctype %} diff --git a/sphinx/theming.py b/sphinx/theming.py index 33c4c76be..bfd7e68ae 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 f28ee82cc..24fe8660e 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 typing import Generator, List # NOQA from sphinx.application import Sphinx # NOQA from sphinx.config import Config # NOQA @@ -376,7 +376,7 @@ class SphinxSmartQuotes(SmartQuotes, SphinxTransform): return False # confirm selected language supports smart_quotes or not - language = self.env.settings['language_code'] + language = self.env.settings['language_code'] # type: ignore for tag in normalize_language_tag(language): if tag in smartchars.quotes: return True diff --git a/sphinx/transforms/compact_bullet_list.py b/sphinx/transforms/compact_bullet_list.py index 0121dd12f..6e4bb0929 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 6adf5eeed..dfdbd0e95 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 ea249b41a..e1f8260a3 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 40f13c549..ac0f2d37c 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 6a28432e3..6ed9196f7 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -24,6 +24,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 @@ -48,8 +49,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 7663feb1e..cf9604f09 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 202616337..dc5a16b68 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 bc4b96a56..bc0b2d301 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 50483d3f1..0fb544f49 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 7caf40275..9b9725810 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 4989de1c9..c11f59381 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 9abe748e4..b3bad1769 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 b0c79ac37..337d3f76a 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) @@ -390,7 +390,8 @@ class Signature(object): # insert '*' between POSITIONAL args and KEYWORD_ONLY args:: # func(a, b, *, c, d): if param.kind == param.KEYWORD_ONLY and last_kind in (param.POSITIONAL_OR_KEYWORD, - param.POSITIONAL_ONLY): + param.POSITIONAL_ONLY, + None): args.append('*') if param.kind in (param.POSITIONAL_ONLY, diff --git a/sphinx/util/inventory.py b/sphinx/util/inventory.py index ed4e55bc2..4ed12e2da 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 6776691cf..2226475f6 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 fbaa72978..29e6a1a88 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 1ac4fb327..2ab4f705e 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 bddf84f5c..08fb1680e 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 f439c515e..9b1e81490 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 21464bbe6..d66ebe89e 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 @@ -22,13 +23,13 @@ import time import warnings from io import BytesIO, StringIO from os import path +from typing import TYPE_CHECKING from six import PY2, PY3, text_type from sphinx.deprecation import RemovedInSphinx30Warning -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 fe2577308..be83a40ac 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 8bcf7e4f8..f1d044a73 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 b6c0d1ab8..2eab6e3ec 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 a406e0044..e2e68f6d0 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 03fc1816c..c34d4daad 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 43a351f65..b31b42270 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 5a415d329..90354e6f2 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 a855cb8fe..d9bb8bd93 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 16a1e48ac..722e595ac 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 21d7626ef..4a265594e 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 f7900b8b3..2fad9f4f1 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 38954ca81..f647a7cf9 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 cce269479..3767ba3fc 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 5e870efa2..12103042f 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 f94fe847c..b40d05ab7 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 diff --git a/tests/conftest.py b/tests/conftest.py index 9fb06edab..67560d009 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -21,6 +21,9 @@ pytest_plugins = 'sphinx.testing.fixtures' collect_ignore = ['roots'] # Disable Python version-specific +if sys.version_info < (3,): + collect_ignore += ['py3'] + if sys.version_info < (3, 5): collect_ignore += ['py35'] diff --git a/tests/py3/test_util_inspect_py3.py b/tests/py3/test_util_inspect_py3.py new file mode 100644 index 000000000..6d02025f9 --- /dev/null +++ b/tests/py3/test_util_inspect_py3.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +""" + py3/test_util_inspect + ~~~~~~~~~~~~~~~~~~~~~ + + Tests util.inspect functions. + + :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from sphinx.util import inspect + + +def test_Signature_keyword_only_arguments(): + def func1(arg1, arg2, *, arg3=None, arg4=None): + pass + + def func2(*, arg3, arg4): + pass + + sig = inspect.Signature(func1).format_args() + assert sig == '(arg1, arg2, *, arg3=None, arg4=None)' + + sig = inspect.Signature(func2).format_args() + assert sig == '(*, arg3, arg4)' diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index af4b771d8..1057a6867 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -767,7 +767,8 @@ def test_image_in_section(app, status, warning): assert ('\\chapter{Another section}' in result) -@pytest.mark.sphinx('latex', confoverrides={'latex_logo': 'notfound.jpg'}) +@pytest.mark.sphinx('latex', testroot='basic', + confoverrides={'latex_logo': 'notfound.jpg'}) def test_latex_logo_if_not_found(app, status, warning): try: app.builder.build_all() diff --git a/utils/release-checklist b/utils/release-checklist index 7ba062a4d..4c5ca4db6 100644 --- a/utils/release-checklist +++ b/utils/release-checklist @@ -5,23 +5,23 @@ for stable releases ------------------- * open https://travis-ci.org/sphinx-doc/sphinx/branches and check **X.Y** branch is green -* Run `git fetch; git status` and check nothing changed -* `python utils/bump_version.py X.Y.Z` -* Check diff by `git diff` +* Run ``git fetch; git status`` and check nothing changed +* ``python utils/bump_version.py X.Y.Z`` +* Check diff by ``git diff`` * Edit CHANGES if empty section exists -* `git commit -am 'Bump to X.Y.Z final'` -* `make clean` -* `python setup.py release bdist_wheel sdist upload --identity=[your key]` +* ``git commit -am 'Bump to X.Y.Z final'`` +* ``make clean`` +* ``python setup.py release bdist_wheel sdist upload --identity=[your key]`` * open https://pypi.python.org/pypi/Sphinx and check there are no obvious errors -* `git tag vX.Y.Z` -* `python utils/bump_version.py --in-develop X.Y.Zb0` (ex. 1.5.3b0) +* ``git tag vX.Y.Z`` +* ``python utils/bump_version.py --in-develop X.Y.Zb0`` (ex. 1.5.3b0) * Check diff by `git diff` -* `git commit -am 'Bump version'` -* `git push origin X.Y --tags` -* `git checkout master` -* `git merge X.Y` -* `git push origin master` -* Update `sphinx-doc-translations `_ +* ``git commit -am 'Bump version'`` +* ``git push origin X.Y --tags`` +* ``git checkout master`` +* ``git merge X.Y`` +* ``git push origin master`` +* Update ``sphinx-doc-translations ``_ * Add new version/milestone to tracker categories * Write announcement and send to sphinx-dev, sphinx-users and python-announce @@ -29,28 +29,28 @@ for first beta releases ----------------------- * open https://travis-ci.org/sphinx-doc/sphinx/branches and check **master** branch is green -* Run `git fetch; git status` and check nothing changed -* Run `python setup.py extract_messages` -* Run `(cd sphinx/locale; tx push -s)` -* `python utils/bump_version.py X.Y.0b1` -* Check diff by `git diff` +* Run ``git fetch; git status`` and check nothing changed +* Run ``python setup.py extract_messages`` +* Run ``(cd sphinx/locale; tx push -s)`` +* ``python utils/bump_version.py X.Y.0b1`` +* Check diff by ``git diff`` * Edit CHANGES if empty section exists -* `git commit -am 'Bump to X.Y.0 beta1'` -* `make clean` -* `python setup.py release bdist_wheel sdist upload --identity=[your key]` +* ``git commit -am 'Bump to X.Y.0 beta1'`` +* ``make clean`` +* ``python setup.py release bdist_wheel sdist upload --identity=[your key]`` * open https://pypi.python.org/pypi/Sphinx and check there are no obvious errors -* `git tag vX.Y.0b1` -* `python utils/bump_version.py --in-develop X.Y.0b2` (ex. 1.6.0b2) -* Check diff by `git diff` -* `git commit -am 'Bump version'` -* `git checkout -b X.Y` -* `git push origin X.Y --tags` -* `git checkout master` -* `git merge X.Y` -* `python utils/bump_version.py --in-develop A.B.0b0` (ex. 1.7.0b0) -* Check diff by `git diff` -* `git commit -am 'Bump version'` -* `git push origin master` +* ``git tag vX.Y.0b1`` +* ``python utils/bump_version.py --in-develop X.Y.0b2`` (ex. 1.6.0b2) +* Check diff by `git diff`` +* ``git commit -am 'Bump version'`` +* ``git checkout -b X.Y`` +* ``git push origin X.Y --tags`` +* ``git checkout master`` +* ``git merge X.Y`` +* ``python utils/bump_version.py --in-develop A.B.0b0`` (ex. 1.7.0b0) +* Check diff by ``git diff`` +* ``git commit -am 'Bump version'`` +* ``git push origin master`` * open https://github.com/sphinx-doc/sphinx/settings/branches and make ``X.Y`` branch protected * Update `sphinx-doc-translations `_ * Add new version/milestone to tracker categories @@ -60,22 +60,22 @@ for other beta releases ----------------------- * open https://travis-ci.org/sphinx-doc/sphinx/branches and check **X.Y** branch is green -* Run `git fetch; git status` and check nothing changed -* `python utils/bump_version.py X.Y.0bN` -* Check diff by `git diff` +* Run ``git fetch; git status`` and check nothing changed +* ``python utils/bump_version.py X.Y.0bN`` +* Check diff by ``git diff`` * Edit CHANGES if empty section exists -* `git commit -am 'Bump to X.Y.0 betaN'` -* `make clean` -* `python setup.py release bdist_wheel sdist upload --identity=[your key]` +* ``git commit -am 'Bump to X.Y.0 betaN'`` +* ``make clean`` +* ``python setup.py release bdist_wheel sdist upload --identity=[your key]`` * open https://pypi.python.org/pypi/Sphinx and check there are no obvious errors -* `git tag vX.Y.0bN` -* `python utils/bump_version.py --in-develop X.Y.0bM` (ex. 1.6.0b3) -* Check diff by `git diff` -* `git commit -am 'Bump version'` -* `git push origin X.Y --tags` -* `git checkout master` -* `git merge X.Y` -* `git push origin master` +* ``git tag vX.Y.0bN`` +* ``python utils/bump_version.py --in-develop X.Y.0bM`` (ex. 1.6.0b3) +* Check diff by `git diff`` +* ``git commit -am 'Bump version'`` +* ``git push origin X.Y --tags`` +* ``git checkout master`` +* ``git merge X.Y`` +* ``git push origin master`` * Update `sphinx-doc-translations `_ * Add new version/milestone to tracker categories * Write announcement and send to sphinx-dev, sphinx-users and python-announce @@ -84,30 +84,30 @@ for major releases ------------------ * open https://travis-ci.org/sphinx-doc/sphinx/branches and check **X.Y** branch is green -* Run `git fetch; git status` and check nothing changed -* Run `(cd sphinx/locale; tx pull -a -f)` -* Run `python setup.py compile_catalog` -* Run `git add sphinx` -* Run `git commit -am 'Update message catalogs'` -* `python utils/bump_version.py X.Y.0` -* Check diff by `git diff` +* Run ``git fetch; git status`` and check nothing changed +* Run ``(cd sphinx/locale; tx pull -a -f)`` +* Run ``python setup.py compile_catalog`` +* Run ``git add sphinx`` +* Run ``git commit -am 'Update message catalogs'`` +* ``python utils/bump_version.py X.Y.0`` +* Check diff by ``git diff`` * Edit CHANGES if empty section exists -* `git commit -am 'Bump to X.Y.0 final'` -* `make clean` -* `python setup.py release bdist_wheel sdist upload --identity=[your key]` +* ``git commit -am 'Bump to X.Y.0 final'`` +* ``make clean`` +* ``python setup.py release bdist_wheel sdist upload --identity=[your key]`` * open https://pypi.python.org/pypi/Sphinx and check there are no obvious errors -* `git tag vX.Y.0` -* `python utils/bump_version.py --in-develop X.Y.1b0` (ex. 1.6.1b0) -* Check diff by `git diff` -* `git commit -am 'Bump version'` -* `git push origin X.Y --tags` -* `git checkout master` -* `git merge X.Y` -* `git push origin master` +* ``git tag vX.Y.0`` +* ``python utils/bump_version.py --in-develop X.Y.1b0`` (ex. 1.6.1b0) +* Check diff by ``git diff`` +* ``git commit -am 'Bump version'`` +* ``git push origin X.Y --tags`` +* ``git checkout master`` +* ``git merge X.Y`` +* ``git push origin master`` * open https://github.com/sphinx-doc/sphinx/settings/branches and make ``A.B`` branch *not* protected -* `git checkout A.B` (checkout old stable) -* Run `git tag A.B` to paste a tag instead branch -* Run `git push origin :A.B --tags` to remove old stable branch +* ``git checkout A.B`` (checkout old stable) +* Run ``git tag A.B`` to paste a tag instead branch +* Run ``git push origin :A.B --tags`` to remove old stable branch * open https://readthedocs.org/dashboard/sphinx/versions/ and enable the released version * Update `sphinx-doc-translations `_ * Add new version/milestone to tracker categories