From 795ca7a0c9fc6dfae8dc5f8a079a8db36a1d05e4 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Mon, 12 Feb 2018 22:44:16 +0900 Subject: [PATCH 01/17] Fix #4260: autodoc: keyword only argument separator is not disappeared --- CHANGES | 3 +++ sphinx/util/inspect.py | 3 ++- tests/conftest.py | 3 +++ tests/py3/test_util_inspect_py3.py | 26 ++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/py3/test_util_inspect_py3.py diff --git a/CHANGES b/CHANGES index 0f1021d77..466cebeb5 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,9 @@ Features added Bugs fixed ---------- +* #4260: autodoc: keyword only argument separator is not disappeared if it is + appeared at top of the argument list + Testing -------- diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 6fd5c789c..318758623 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -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/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)' From 7cf1520c10302ffadc5adc704f0623c07391cff8 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 13 Feb 2018 21:00:46 +0900 Subject: [PATCH 02/17] Fix #4608: epub: Invalid meta tag is generated --- CHANGES | 2 ++ sphinx/builders/epub3.py | 1 + sphinx/themes/basic/layout.html | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 0f1021d77..c8fa73ce5 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,8 @@ Features added Bugs fixed ---------- +* #4608: epub: Invalid meta tag is generated + Testing -------- diff --git a/sphinx/builders/epub3.py b/sphinx/builders/epub3.py index bb18e9c9b..0ea0dcf27 100644 --- a/sphinx/builders/epub3.py +++ b/sphinx/builders/epub3.py @@ -143,6 +143,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/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 %} From 91807f882dafbd6185b8d88c0bf4cbf97cf520fb Mon Sep 17 00:00:00 2001 From: Thijs Triemstra Date: Mon, 12 Feb 2018 22:57:05 +0100 Subject: [PATCH 03/17] fix broken links on pypi page --- README.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 2d841f78e..82f61710b 100644 --- a/README.rst +++ b/README.rst @@ -72,7 +72,7 @@ If you wish to install `Sphinx` for development purposes, refer to `the contributors guide`__. __ https://pypi.python.org/pypi/Sphinx -__ CONTRIBUTING.rst +__ http://www.sphinx-doc.org/en/master/devguide.html Documentation ============= @@ -93,14 +93,14 @@ For information on running tests locally, refer to `the contributors guide`__. __ https://travis-ci.org/sphinx-doc/sphinx __ https://ci.appveyor.com/project/sphinxdoc/sphinx __ https://circleci.com/gh/sphinx-doc/sphinx -__ CONTRIBUTING.rst +__ http://www.sphinx-doc.org/en/master/devguide.html Contributing ============ Refer to `the contributors guide`__. -__ CONTRIBUTING.rst +__ http://www.sphinx-doc.org/en/master/devguide.html Release signatures ================== From 5b02d61a04e8a8470cc92674d670b385c71df3f5 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 14 Feb 2018 01:34:50 +0900 Subject: [PATCH 04/17] Use roots/basic for test_latex_logo_if_not_found --- tests/test_build_latex.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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() From a073e17537c2aacaac305feadea58d4473ec97f4 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 14 Feb 2018 22:57:20 +0900 Subject: [PATCH 05/17] Use typing.TYPE_CHECKING for typehints --- sphinx/addnodes.py | 5 +++-- sphinx/application.py | 4 ++-- sphinx/builders/__init__.py | 4 ++-- sphinx/builders/_epub_base.py | 4 ++-- sphinx/builders/applehelp.py | 4 ++-- sphinx/builders/changes.py | 4 ++-- sphinx/builders/devhelp.py | 4 ++-- sphinx/builders/dummy.py | 4 ++-- sphinx/builders/epub3.py | 4 ++-- sphinx/builders/gettext.py | 4 ++-- sphinx/builders/html.py | 4 ++-- sphinx/builders/htmlhelp.py | 4 ++-- sphinx/builders/latex.py | 4 ++-- sphinx/builders/linkcheck.py | 4 ++-- sphinx/builders/manpage.py | 4 ++-- sphinx/builders/qthelp.py | 4 ++-- sphinx/builders/texinfo.py | 4 ++-- sphinx/builders/text.py | 4 ++-- sphinx/builders/websupport.py | 5 +++-- sphinx/builders/xml.py | 4 ++-- sphinx/cmd/build.py | 4 ++-- sphinx/cmd/quickstart.py | 4 ++-- sphinx/cmdline.py | 4 ++-- sphinx/config.py | 5 ++--- sphinx/directives/__init__.py | 4 ++-- sphinx/directives/code.py | 4 ++-- sphinx/directives/other.py | 5 +++-- sphinx/directives/patches.py | 5 +++-- sphinx/domains/__init__.py | 4 ++-- sphinx/domains/c.py | 4 ++-- sphinx/domains/cpp.py | 4 ++-- sphinx/domains/javascript.py | 5 +++-- sphinx/domains/python.py | 4 ++-- sphinx/domains/rst.py | 4 ++-- sphinx/domains/std.py | 4 ++-- sphinx/environment/__init__.py | 4 ++-- sphinx/environment/adapters/asset.py | 5 +++-- sphinx/environment/adapters/indexentries.py | 4 ++-- sphinx/environment/adapters/toctree.py | 5 +++-- sphinx/environment/collectors/__init__.py | 5 +++-- sphinx/environment/collectors/asset.py | 4 ++-- sphinx/environment/collectors/dependencies.py | 4 ++-- sphinx/environment/collectors/indexentries.py | 5 +++-- sphinx/environment/collectors/metadata.py | 5 +++-- sphinx/environment/collectors/title.py | 5 +++-- sphinx/environment/collectors/toctree.py | 5 +++-- sphinx/errors.py | 5 +++-- sphinx/events.py | 4 ++-- sphinx/ext/apidoc.py | 4 ++-- sphinx/ext/autodoc/__init__.py | 4 ++-- sphinx/ext/autodoc/directive.py | 5 +++-- sphinx/ext/autodoc/importer.py | 4 ++-- sphinx/ext/autodoc/inspector.py | 4 ++-- sphinx/ext/autosectionlabel.py | 4 +++- sphinx/ext/autosummary/__init__.py | 4 ++-- sphinx/ext/autosummary/generate.py | 4 ++-- sphinx/ext/coverage.py | 4 ++-- sphinx/ext/doctest.py | 4 ++-- sphinx/ext/graphviz.py | 4 ++-- sphinx/ext/ifconfig.py | 5 +++-- sphinx/ext/imgconverter.py | 4 ++-- sphinx/ext/imgmath.py | 4 ++-- sphinx/ext/inheritance_diagram.py | 4 ++-- sphinx/ext/intersphinx.py | 4 ++-- sphinx/ext/linkcode.py | 5 +++-- sphinx/ext/mathbase.py | 5 +++-- sphinx/ext/napoleon/__init__.py | 4 ++-- sphinx/ext/napoleon/docstring.py | 4 ++-- sphinx/ext/napoleon/iterators.py | 4 ++-- sphinx/ext/pngmath.py | 4 ++-- sphinx/ext/todo.py | 5 +++-- sphinx/ext/viewcode.py | 4 ++-- sphinx/extension.py | 5 +++-- sphinx/highlighting.py | 5 +++-- sphinx/io.py | 4 ++-- sphinx/jinja2glue.py | 5 ++--- sphinx/locale/__init__.py | 4 ++-- sphinx/make_mode.py | 4 ++-- sphinx/parsers.py | 5 +++-- sphinx/pycode/__init__.py | 5 +++-- sphinx/pycode/parser.py | 4 ++-- sphinx/registry.py | 4 ++-- sphinx/roles.py | 4 ++-- sphinx/search/__init__.py | 4 ++-- sphinx/search/da.py | 2 ++ sphinx/search/de.py | 2 ++ sphinx/search/en.py | 5 +++-- sphinx/search/es.py | 2 ++ sphinx/search/fi.py | 2 ++ sphinx/search/fr.py | 2 ++ sphinx/search/hu.py | 2 ++ sphinx/search/it.py | 2 ++ sphinx/search/ja.py | 4 ++-- sphinx/search/nl.py | 2 ++ sphinx/search/no.py | 2 ++ sphinx/search/pt.py | 2 ++ sphinx/search/ro.py | 5 +++-- sphinx/search/ru.py | 2 ++ sphinx/search/sv.py | 2 ++ sphinx/search/tr.py | 5 +++-- sphinx/search/zh.py | 4 ++-- sphinx/setup_command.py | 4 ++-- sphinx/testing/fixtures.py | 3 ++- sphinx/testing/util.py | 3 ++- sphinx/theming.py | 4 ++-- sphinx/transforms/__init__.py | 4 ++-- sphinx/transforms/compact_bullet_list.py | 5 +++-- sphinx/transforms/i18n.py | 4 ++-- sphinx/transforms/post_transforms/__init__.py | 4 ++-- sphinx/transforms/post_transforms/images.py | 4 ++-- sphinx/util/__init__.py | 4 ++-- sphinx/util/console.py | 5 +++-- sphinx/util/docfields.py | 5 +++-- sphinx/util/docstrings.py | 5 +++-- sphinx/util/docutils.py | 4 ++-- sphinx/util/fileutil.py | 4 ++-- sphinx/util/i18n.py | 6 ++++-- sphinx/util/images.py | 5 ++--- sphinx/util/inspect.py | 4 ++-- sphinx/util/inventory.py | 6 ++++-- sphinx/util/jsdump.py | 5 +++-- sphinx/util/jsonimpl.py | 5 +++-- sphinx/util/logging.py | 4 ++-- sphinx/util/matching.py | 5 +++-- sphinx/util/nodes.py | 4 ++-- sphinx/util/osutil.py | 5 +++-- sphinx/util/parallel.py | 5 +++-- sphinx/util/pycompat.py | 5 +++-- sphinx/util/requests.py | 4 ++-- sphinx/util/rst.py | 4 ++-- sphinx/util/smartypants.py | 3 ++- sphinx/util/tags.py | 6 ++++-- sphinx/util/template.py | 5 +++-- sphinx/versioning.py | 4 ++-- sphinx/writers/html.py | 4 ++-- sphinx/writers/html5.py | 4 ++-- sphinx/writers/latex.py | 4 ++-- sphinx/writers/manpage.py | 5 +++-- sphinx/writers/texinfo.py | 4 ++-- sphinx/writers/text.py | 4 ++-- sphinx/writers/xml.py | 5 +++-- 141 files changed, 327 insertions(+), 257 deletions(-) diff --git a/sphinx/addnodes.py b/sphinx/addnodes.py index 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 0305f7560..1495d6eaf 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -18,6 +18,7 @@ import sys import warnings from collections import deque from os import path +from typing import TYPE_CHECKING from docutils import nodes from docutils.parsers.rst import directives, roles @@ -43,8 +44,7 @@ from sphinx.util.i18n import find_catalog_source_files from sphinx.util.osutil import ENOENT, ensuredir from sphinx.util.tags import Tags -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, IO, Iterable, Iterator, List, Tuple, Type, Union # NOQA from docutils.parsers import Parser # NOQA from docutils.transform import Transform # NOQA diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index 5c4714e8f..2cd418ce3 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 96e06afdc..13e0beb28 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 0ea0dcf27..da252b359 100644 --- a/sphinx/builders/epub3.py +++ b/sphinx/builders/epub3.py @@ -12,6 +12,7 @@ from collections import namedtuple from os import path +from typing import TYPE_CHECKING from sphinx import package_dir from sphinx.builders import _epub_base @@ -21,8 +22,7 @@ from sphinx.util.fileutil import copy_asset_file from sphinx.util.i18n import format_date from sphinx.util.osutil import make_filename -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, Iterable, List # NOQA from docutils import nodes # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/builders/gettext.py b/sphinx/builders/gettext.py index 6f38816df..a5cca6a47 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 e2f3909cc..c1bb4dbf2 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -16,6 +16,7 @@ import sys import warnings from hashlib import md5 from os import path +from typing import TYPE_CHECKING import docutils from docutils import nodes @@ -51,8 +52,7 @@ from sphinx.util.osutil import SEP, os_path, relative_uri, ensuredir, \ movefile, copyfile from sphinx.writers.html import HTMLWriter, HTMLTranslator -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, IO, Iterable, Iterator, List, Type, Tuple, Union # NOQA from sphinx.application import Sphinx # NOQA from sphinx.config import Config # NOQA diff --git a/sphinx/builders/htmlhelp.py b/sphinx/builders/htmlhelp.py index 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 c66d00d4f..55d1f99d1 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 8a10a4f2c..c29c7ab06 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..795d140d3 100644 --- a/sphinx/cmd/quickstart.py +++ b/sphinx/cmd/quickstart.py @@ -19,6 +19,7 @@ import time from collections import OrderedDict from io import open from os import path +from typing import TYPE_CHECKING # try to import readline, unix specific enhancement try: @@ -43,8 +44,7 @@ from sphinx.util.console import ( # type: ignore from sphinx.util.osutil import ensuredir, make_filename from sphinx.util.template import SphinxRenderer -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, List, Pattern, Union # NOQA TERM_ENCODING = getattr(sys.stdin, 'encoding', None) diff --git a/sphinx/cmdline.py b/sphinx/cmdline.py index 908da68d8..2fa06a1ab 100644 --- a/sphinx/cmdline.py +++ b/sphinx/cmdline.py @@ -15,6 +15,7 @@ import multiprocessing import sys import traceback from os import path +from typing import TYPE_CHECKING from docutils.utils import SystemMessage from six import text_type, binary_type @@ -28,8 +29,7 @@ from sphinx.util.docutils import docutils_namespace, patch_docutils from sphinx.util.osutil import abspath, fs_encoding from sphinx.util.pycompat import terminal_safe -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, IO, List, Union # NOQA diff --git a/sphinx/config.py b/sphinx/config.py index 1f80ab366..4f8bf969d 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -12,7 +12,7 @@ import re import traceback from os import path, getenv -from typing import Any, NamedTuple, Union +from typing import TYPE_CHECKING, Any, NamedTuple, Union from six import PY2, PY3, iteritems, string_types, binary_type, text_type, integer_types @@ -23,8 +23,7 @@ from sphinx.util.i18n import format_date from sphinx.util.osutil import cd from sphinx.util.pycompat import execfile_, NoneType -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, Iterable, Iterator, List, Tuple, Union # NOQA from sphinx.util.tags import Tags # NOQA diff --git a/sphinx/directives/__init__.py b/sphinx/directives/__init__.py index 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 ae67cf4c6..91b8661b4 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 c97340a81..cb8ca31fa 100644 --- a/sphinx/directives/patches.py +++ b/sphinx/directives/patches.py @@ -7,6 +7,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes from docutils.parsers.rst import directives from docutils.parsers.rst.directives import images, html, tables @@ -14,8 +16,7 @@ from docutils.parsers.rst.directives import images, html, tables from sphinx import addnodes from sphinx.util.nodes import set_source_info -if False: - # For type annotation +if TYPE_CHECKING: from typing import Dict, List # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/domains/__init__.py b/sphinx/domains/__init__.py index c68d37472..3ae957fec 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 f0c81db7b..3f6a57815 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 625bbe81e..c7bb82203 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 734969fc1..037f1048b 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 5456ca13a..a87c0482e 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 c14eb180f..f356704bf 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 ad56da63d..78159808d 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 5a05ce26f..b53fec888 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -18,6 +18,7 @@ import warnings from collections import defaultdict from copy import copy from os import path +from typing import TYPE_CHECKING from docutils.frontend import OptionParser from docutils.utils import Reporter, get_source_line @@ -42,8 +43,7 @@ from sphinx.util.osutil import SEP, ensuredir from sphinx.util.parallel import ParallelTasks, parallel_available, make_chunks from sphinx.util.websupport import is_commentable -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, IO, Iterator, List, Optional, Pattern, Set, Tuple, Type, Union, Generator # NOQA from docutils import nodes # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/environment/adapters/asset.py b/sphinx/environment/adapters/asset.py index 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 a7556eadd..e17c1db39 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 eef1a157a..34c0cae33 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 097f61fc6..de9def1b9 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 07c399f25..642bcf087 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 0f7231f7a..a02286c28 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -15,6 +15,7 @@ import inspect import re import sys import warnings +from typing import TYPE_CHECKING from docutils.statemachine import ViewList from six import iteritems, itervalues, text_type, class_types, string_types @@ -34,8 +35,7 @@ from sphinx.util.inspect import Signature, isdescriptor, safe_getmembers, \ safe_getattr, object_description, is_builtin_class_method, \ isenumattribute, isclassmethod, isstaticmethod, getdoc -if False: - # For type annotation +if TYPE_CHECKING: from types import ModuleType # NOQA from typing import Any, Callable, Dict, Iterator, List, Sequence, Set, Tuple, Type, Union # NOQA from docutils import nodes # NOQA diff --git a/sphinx/ext/autodoc/directive.py b/sphinx/ext/autodoc/directive.py index 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 618b56378..db33b4215 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 6a3ff1422..c01f5ef4b 100644 --- a/sphinx/ext/autosectionlabel.py +++ b/sphinx/ext/autosectionlabel.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes from sphinx.util import logging @@ -16,7 +18,7 @@ from sphinx.util.nodes import clean_astext logger = logging.getLogger(__name__) -if False: +if TYPE_CHECKING: # For type annotation from typing import Any, Dict # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index a2aa210fc..4728281c3 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 2818ab3c7..4c67831af 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 2986bf9c1..da3e55b60 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 95f579e36..3c8d499e3 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 5d373c689..8d84af7d7 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 24c10df3c..15218963f 100644 --- a/sphinx/ext/mathbase.py +++ b/sphinx/ext/mathbase.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from docutils import nodes, utils from docutils.nodes import make_id from docutils.parsers.rst import Directive, directives @@ -20,8 +22,7 @@ from sphinx.roles import XRefRole from sphinx.util import logging from sphinx.util.nodes import make_refnode, set_source_info -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, Iterable, List, Tuple # NOQA from docutils.parsers.rst.states import Inliner # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/ext/napoleon/__init__.py b/sphinx/ext/napoleon/__init__.py index b65f7f2a1..90374692c 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 b349c761f..3c38f4141 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -14,6 +14,7 @@ import collections import inspect import re +from typing import TYPE_CHECKING from six import string_types, u from six.moves import range @@ -21,8 +22,7 @@ from six.moves import range from sphinx.ext.napoleon.iterators import modify_iter from sphinx.util.pycompat import UnicodeMixin -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, List, Tuple, Union # NOQA from sphinx.application import Sphinx # NOQA from sphinx.config import Config as SphinxConfig # NOQA diff --git a/sphinx/ext/napoleon/iterators.py b/sphinx/ext/napoleon/iterators.py index 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 fd3d5c062..19378f6b5 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 9ba76c9c9..54c1c8923 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 aa1157ec8..feb23b899 100644 --- a/sphinx/extension.py +++ b/sphinx/extension.py @@ -9,14 +9,15 @@ :license: BSD, see LICENSE for details. """ +from typing import TYPE_CHECKING + from six import iteritems from sphinx.errors import VersionRequirementError from sphinx.locale import __ from sphinx.util import logging -if False: - # For type annotation +if TYPE_CHECKING: from typing import Dict # NOQA from sphinx.application import Sphinx # NOQA diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py index 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 8f1da22bd..88fee462f 100644 --- a/sphinx/io.py +++ b/sphinx/io.py @@ -10,6 +10,7 @@ """ import codecs import re +from typing import TYPE_CHECKING from docutils.core import Publisher from docutils.io import FileInput, NullOutput @@ -33,8 +34,7 @@ from sphinx.transforms.i18n import ( from sphinx.util import logging from sphinx.util.docutils import LoggingReporter -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Dict, List, Tuple, Union # NOQA from docutils import nodes # NOQA from docutils.io import Input # NOQA diff --git a/sphinx/jinja2glue.py b/sphinx/jinja2glue.py index cc935d577..4dac0210a 100644 --- a/sphinx/jinja2glue.py +++ b/sphinx/jinja2glue.py @@ -11,7 +11,7 @@ from os import path from pprint import pformat -from typing import Any, Callable, Iterator, Tuple # NOQA +from typing import TYPE_CHECKING, Any, Callable, Iterator, Tuple # NOQA from jinja2 import FileSystemLoader, BaseLoader, TemplateNotFound, \ contextfunction @@ -22,8 +22,7 @@ from six import string_types from sphinx.application import TemplateBridge from sphinx.util.osutil import mtimes_of_files -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, List, Iterator, Tuple # NOQA from jinja2.environment import Environment # NOQA from sphinx.builders import Builder # NOQA diff --git a/sphinx/locale/__init__.py b/sphinx/locale/__init__.py index 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 34822898f..57344ddb3 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 de951a19f..04e63b728 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 f15da664a..c5d9be320 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 28da0435e..3ab3a69a0 100644 --- a/sphinx/registry.py +++ b/sphinx/registry.py @@ -11,6 +11,7 @@ from __future__ import print_function import traceback +from typing import TYPE_CHECKING from pkg_resources import iter_entry_points from six import iteritems, itervalues, string_types @@ -27,8 +28,7 @@ from sphinx.util import logging from sphinx.util.console import bold # type: ignore from sphinx.util.docutils import directive_helper -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, Iterator, List, Type, Union # NOQA from docutils import nodes # NOQA from docutils.io import Input # NOQA diff --git a/sphinx/roles.py b/sphinx/roles.py index 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 b3611152a..2602aea3b 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 89cbe3de5..babb5bb9e 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 2777811d8..4fff081bb 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 ca63b0021..2f334ab24 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 615a47383..7bd4abd31 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 85d15bac7..a1c4bab2c 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 b613ce33c..7239fdef4 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 b2ab4e0f0..5a13af1da 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 32f7b38c5..0be73a26d 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 ba9f2529b..2974d0424 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 8eb6c3dbb..7df587a25 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 64883381e..c18c85487 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 1f160fec1..30553f827 100644 --- a/sphinx/setup_command.py +++ b/sphinx/setup_command.py @@ -17,6 +17,7 @@ import os import sys from distutils.cmd import Command from distutils.errors import DistutilsOptionError, DistutilsExecError # type: ignore +from typing import TYPE_CHECKING from six import StringIO, string_types @@ -26,8 +27,7 @@ from sphinx.util.console import nocolor, color_terminal from sphinx.util.docutils import docutils_namespace, patch_docutils from sphinx.util.osutil import abspath -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, List, Tuple # NOQA diff --git a/sphinx/testing/fixtures.py b/sphinx/testing/fixtures.py index be0037b70..0ef072a46 100644 --- a/sphinx/testing/fixtures.py +++ b/sphinx/testing/fixtures.py @@ -15,13 +15,14 @@ import subprocess import sys from collections import namedtuple from tempfile import gettempdir +from typing import TYPE_CHECKING import pytest from six import StringIO, string_types from . import util -if False: +if TYPE_CHECKING: from typing import Dict, Union # NOQA diff --git a/sphinx/testing/util.py b/sphinx/testing/util.py index 60544cfa3..a1e564015 100644 --- a/sphinx/testing/util.py +++ b/sphinx/testing/util.py @@ -12,6 +12,7 @@ import os import re import sys import warnings +from typing import TYPE_CHECKING from xml.etree import ElementTree from docutils import nodes @@ -24,7 +25,7 @@ from sphinx.ext.autodoc import AutoDirective from sphinx.pycode import ModuleAnalyzer from sphinx.testing.path import path -if False: +if TYPE_CHECKING: from typing import List # NOQA diff --git a/sphinx/theming.py b/sphinx/theming.py index 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 a2e92223d..73513598c 100644 --- a/sphinx/transforms/__init__.py +++ b/sphinx/transforms/__init__.py @@ -10,6 +10,7 @@ """ import re +from typing import TYPE_CHECKING from docutils import nodes from docutils.transforms import Transform, Transformer @@ -25,8 +26,7 @@ from sphinx.util.docutils import new_document from sphinx.util.i18n import format_date from sphinx.util.nodes import apply_source_workaround, is_smartquotable -if False: - # For type annotation +if TYPE_CHECKING: from sphinx.application import Sphinx # NOQA from sphinx.config import Config # NOQA from sphinx.domain.std import StandardDomain # NOQA diff --git a/sphinx/transforms/compact_bullet_list.py b/sphinx/transforms/compact_bullet_list.py index 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 bb85c76bd..b4b3f8388 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 b8f4b9a5d..c107f832e 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 dda3fb04c..3cd429b3c 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -23,6 +23,7 @@ from collections import deque from datetime import datetime from os import path from time import mktime, strptime +from typing import TYPE_CHECKING from docutils.utils import relative_path from six import text_type, binary_type, itervalues @@ -46,8 +47,7 @@ from sphinx.util.nodes import ( # noqa caption_ref_re) from sphinx.util.matching import patfilter # noqa -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, IO, Iterable, Iterator, List, Pattern, Sequence, Set, Tuple, Union # NOQA diff --git a/sphinx/util/console.py b/sphinx/util/console.py index 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 2f952d7cc..f41adf67f 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 dd2f2a9e2..2f4395482 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 6fd5c789c..dd27859a0 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -15,14 +15,14 @@ import re import sys import typing from collections import OrderedDict +from typing import TYPE_CHECKING from six import PY2, PY3, StringIO, binary_type, string_types, itervalues from six.moves import builtins from sphinx.util import force_decode -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Callable, Dict, List, Tuple, Type # NOQA memory_address_re = re.compile(r' at 0x[0-9a-f]{8,16}(?=>)', re.IGNORECASE) diff --git a/sphinx/util/inventory.py b/sphinx/util/inventory.py index 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 09db0028f..6b0afd633 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 af87caf9a..ce68fb8b3 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -8,6 +8,7 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import absolute_import from __future__ import print_function import contextlib @@ -21,11 +22,11 @@ import sys import time from io import BytesIO, StringIO from os import path +from typing import TYPE_CHECKING from six import PY2, PY3, text_type -if False: - # For type annotation +if TYPE_CHECKING: from typing import Any, Iterator, List, Tuple, Union # NOQA # Errnos that we need. diff --git a/sphinx/util/parallel.py b/sphinx/util/parallel.py index 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 bca901b18..97b4e243e 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 bd0928775..f50f6cb4c 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 0fc4a7bea..d9bc1e5dd 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 d84bb81a0..46f4da951 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 From 5d1b8ff55f5bbd67aad1fe14209e13dc526a4b3d Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 14 Feb 2018 22:57:21 +0900 Subject: [PATCH 06/17] Fix mypy violations --- sphinx/application.py | 2 +- sphinx/builders/html.py | 4 ++-- sphinx/environment/__init__.py | 10 +++++----- sphinx/ext/autodoc/__init__.py | 5 +++-- sphinx/io.py | 2 +- sphinx/transforms/__init__.py | 2 +- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/sphinx/application.py b/sphinx/application.py index 1495d6eaf..d118c2afe 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -122,7 +122,7 @@ class Sphinx(object): self.enumerable_nodes = {} # type: Dict[nodes.Node, Tuple[unicode, Callable]] # NOQA self.html_themes = {} # type: Dict[unicode, unicode] - self.srcdir = srcdir + self.srcdir = srcdir # type: unicode self.confdir = confdir self.outdir = outdir self.doctreedir = doctreedir diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index c1bb4dbf2..6fef3e95f 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -594,9 +594,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/environment/__init__.py b/sphinx/environment/__init__.py index b53fec888..94dd4187f 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -169,8 +169,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] @@ -187,7 +187,7 @@ class BuildEnvironment(object): self._warnfunc = None # type: Callable # this is to invalidate old pickles - self.version = ENV_VERSION + self.version = ENV_VERSION # type: int # All "docnames" here are /-separated and relative and exclude # the source suffix. @@ -252,8 +252,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/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index a02286c28..8b9e90e57 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -41,6 +41,7 @@ if TYPE_CHECKING: 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/io.py b/sphinx/io.py index 88fee462f..113322e4b 100644 --- a/sphinx/io.py +++ b/sphinx/io.py @@ -289,7 +289,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/transforms/__init__.py b/sphinx/transforms/__init__.py index 73513598c..12dc18694 100644 --- a/sphinx/transforms/__init__.py +++ b/sphinx/transforms/__init__.py @@ -374,7 +374,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 From 01da85fbe2057036c766c01bb432add40bbaca97 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 15 Feb 2018 01:57:26 +0900 Subject: [PATCH 07/17] Fix #4617: quickstart: PROJECT_DIR argument is required --- CHANGES | 1 + sphinx/cmd/quickstart.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index df83d9b24..5ba7946a6 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,7 @@ 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 +* #4617: quickstart: PROJECT_DIR argument is required Testing -------- diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py index 395c33245..68718eeaf 100644 --- a/sphinx/cmd/quickstart.py +++ b/sphinx/cmd/quickstart.py @@ -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') From 3efc8e957a0261a7f6a02f986831ab4bc1d1097a Mon Sep 17 00:00:00 2001 From: Akihiro Takizawa Date: Thu, 15 Feb 2018 14:28:55 +0900 Subject: [PATCH 08/17] key changes to scheme in epub3 opf template --- sphinx/templates/epub3/content.opf_t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/templates/epub3/content.opf_t b/sphinx/templates/epub3/content.opf_t index faabc86df..224443283 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 }} From 11f543445af96665db848143a5eb2ce0860e1920 Mon Sep 17 00:00:00 2001 From: Akihiro Takizawa Date: Fri, 16 Feb 2018 09:37:00 +0900 Subject: [PATCH 09/17] fix dc.identifier element using opf:scheme in sphinx/templates/epub3/content.opf_t --- sphinx/templates/epub3/content.opf_t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/templates/epub3/content.opf_t b/sphinx/templates/epub3/content.opf_t index 224443283..dc71bb421 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 }} From 8a3f485e59b6e0c1b9d3cbaf80a145b00010b96f Mon Sep 17 00:00:00 2001 From: Akihiro Takizawa Date: Fri, 16 Feb 2018 10:31:50 +0900 Subject: [PATCH 10/17] restore deleted id attribute in dc.identifier element --- sphinx/templates/epub3/content.opf_t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/templates/epub3/content.opf_t b/sphinx/templates/epub3/content.opf_t index dc71bb421..25f57b7b5 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 }} From dc4cb0765c1186821978f180dbc5450ae7b10e08 Mon Sep 17 00:00:00 2001 From: Akihiro Takizawa Date: Fri, 16 Feb 2018 11:09:06 +0900 Subject: [PATCH 11/17] restore deleted id attribute in dc.identifier element --- sphinx/templates/epub3/content.opf_t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/templates/epub3/content.opf_t b/sphinx/templates/epub3/content.opf_t index 25f57b7b5..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 }} From a721b32d5194bc8d85a54978bd51220613034977 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Fri, 16 Feb 2018 21:06:46 +0900 Subject: [PATCH 12/17] docs: Use literal for commands --- utils/release-checklist | 138 ++++++++++++++++++++-------------------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/utils/release-checklist b/utils/release-checklist index dff7e86ec..b7276d8bf 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`` * Update `sphinx-doc-translations `_ * Add new version/milestone to tracker categories * Write announcement and send to sphinx-dev, sphinx-users and python-announce @@ -59,22 +59,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 @@ -83,29 +83,29 @@ 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 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 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 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 From b2e18a08e91dfde11c9738d8ab5963b4bbbc947d Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Fri, 16 Feb 2018 21:42:24 +0900 Subject: [PATCH 13/17] Update CHANGES for PR #4622 --- CHANGES | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES b/CHANGES index df83d9b24..b41da6445 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,8 @@ 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 + Testing -------- From 1d311b3b5c5e0e580d776fb6ea3ab0d8ea2ded96 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 17 Feb 2018 00:16:34 +0900 Subject: [PATCH 14/17] test: allows to drop 0.05% coverages --- .codecov.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .codecov.yml 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 From fd763cb85c4441653a09cb689a71866eef729bdd Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 17 Feb 2018 00:42:38 +0900 Subject: [PATCH 15/17] Load sub packages lazily on sphinx/__init__.py --- sphinx/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sphinx/__init__.py b/sphinx/__init__.py index 49dd0ab8b..c8ce7a7ea 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 @@ -61,6 +60,7 @@ if __version__.endswith('+'): def main(*args, **kwargs): + from .cmd import build warnings.warn( '`sphinx.main()` has moved to `sphinx.cmd.build.main()`.', RemovedInSphinx20Warning, @@ -70,6 +70,7 @@ def main(*args, **kwargs): if __name__ == '__main__': + from .cmd import build warnings.warn( '`sphinx` has moved to `sphinx.build`.', RemovedInSphinx20Warning, From 675b8fe48fd2747bdd2c31dfd7ea0f3dc422da9f Mon Sep 17 00:00:00 2001 From: Roman Kapl Date: Sun, 11 Feb 2018 15:32:59 +0100 Subject: [PATCH 16/17] Fit graphviz images to page. Use \sphinxincludegraphics, that's what the core image directives use and it handles fitting properly. --- sphinx/ext/graphviz.py | 2 +- tests/test_ext_graphviz.py | 8 ++++---- tests/test_ext_inheritance_diagram.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sphinx/ext/graphviz.py b/sphinx/ext/graphviz.py index 2986bf9c1..08707b733 100644 --- a/sphinx/ext/graphviz.py +++ b/sphinx/ext/graphviz.py @@ -341,7 +341,7 @@ def render_dot_latex(self, node, code, options, prefix='graphviz'): post = r'\hspace*{\fill}}' self.body.append('\n%s' % pre) - self.body.append(r'\includegraphics{%s}' % fname) + self.body.append(r'\sphinxincludegraphics[]{%s}' % fname) if not is_inline: self.body.append('%s\n' % post) diff --git a/tests/test_ext_graphviz.py b/tests/test_ext_graphviz.py index ef77135d7..3efab6b56 100644 --- a/tests/test_ext_graphviz.py +++ b/tests/test_ext_graphviz.py @@ -91,20 +91,20 @@ def test_graphviz_latex(app, status, warning): content = (app.outdir / 'SphinxTests.tex').text() macro = ('\\\\begin{figure}\\[htbp\\]\n\\\\centering\n\\\\capstart\n\n' - '\\\\includegraphics{graphviz-\\w+.pdf}\n' + '\\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf}\n' '\\\\caption{caption of graph}\\\\label{.*}\\\\end{figure}') assert re.search(macro, content, re.S) - macro = 'Hello \\\\includegraphics{graphviz-\\w+.pdf} graphviz world' + macro = 'Hello \\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf} graphviz world' assert re.search(macro, content, re.S) macro = ('\\\\begin{wrapfigure}{r}{0pt}\n\\\\centering\n' - '\\\\includegraphics{graphviz-\\w+.pdf}\n' + '\\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf}\n' '\\\\caption{on right}\\\\label{.*}\\\\end{wrapfigure}') assert re.search(macro, content, re.S) macro = (r'\{\\hfill' - r'\\includegraphics{graphviz-.*}' + r'\\sphinxincludegraphics\[\]{graphviz-.*}' r'\\hspace\*{\\fill}}') assert re.search(macro, content, re.S) diff --git a/tests/test_ext_inheritance_diagram.py b/tests/test_ext_inheritance_diagram.py index ed79729e6..ad106e6c6 100644 --- a/tests/test_ext_inheritance_diagram.py +++ b/tests/test_ext_inheritance_diagram.py @@ -40,7 +40,7 @@ def test_inheritance_diagram_latex(app, status, warning): content = (app.outdir / 'Python.tex').text() pattern = ('\\\\begin{figure}\\[htbp]\n\\\\centering\n\\\\capstart\n\n' - '\\\\includegraphics{inheritance-\\w+.pdf}\n' + '\\\\sphinxincludegraphics\\[\\]{inheritance-\\w+.pdf}\n' '\\\\caption{Test Foo!}\\\\label{\\\\detokenize{index:id1}}\\\\end{figure}') assert re.search(pattern, content, re.M) From 08158bf804a010c3afa1b88d33d6db79e1a6ba5d Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 17 Feb 2018 10:07:28 +0900 Subject: [PATCH 17/17] Fix CHANGES for PR #4627 --- CHANGES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index b41da6445..afb8cbbbe 100644 --- a/CHANGES +++ b/CHANGES @@ -20,7 +20,7 @@ Bugs fixed * #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 Testing --------