From d345d0f8c17009195f69b581cc1b6dc2da431b0e Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Fri, 5 Oct 2018 18:02:56 +0100 Subject: [PATCH 1/2] py3: Remove (most) __future__ imports There were two used: - print_function - absolute_import Both of these are mandatory in Python 3.0 onwards [1] and can therefore be removed...mostly. Unfortunately, mypy is still running in Python 2.7 mode, meaning we need the 'print_function' future wherever we're calling 'print' with the 'file' argument. There's also a single 'absolute_import' future that must be retained as its removal breaks a test for as-yet unknown reasons. TODOs are added to resolve both issues in the future. [1] https://docs.python.org/3/library/__future__.html Signed-off-by: Stephen Finucane --- sphinx/__init__.py | 2 -- sphinx/builders/devhelp.py | 1 - sphinx/builders/gettext.py | 2 -- sphinx/cmd/quickstart.py | 1 - sphinx/cmdline.py | 1 - sphinx/ext/doctest.py | 1 - sphinx/util/__init__.py | 1 - sphinx/util/compat.py | 2 -- sphinx/util/docfields.py | 1 - sphinx/util/docutils.py | 1 - sphinx/util/fileutil.py | 1 - sphinx/util/images.py | 1 - sphinx/util/inspect.py | 1 - sphinx/util/logging.py | 1 - sphinx/util/nodes.py | 1 - sphinx/util/parallel.py | 1 - sphinx/util/requests.py | 2 -- sphinx/util/rst.py | 1 - sphinx/util/smartypants.py | 1 - sphinx/util/texescape.py | 2 -- tests/roots/test-ext-autodoc/target/enum.py | 1 - tests/roots/test-ext-viewcode-find/not_a_package/__init__.py | 1 + tests/roots/test-ext-viewcode/spam/__init__.py | 2 -- utils/bump_version.py | 2 -- 24 files changed, 1 insertion(+), 30 deletions(-) diff --git a/sphinx/__init__.py b/sphinx/__init__.py index ac5a91a97d..9711863cea 100644 --- a/sphinx/__init__.py +++ b/sphinx/__init__.py @@ -12,8 +12,6 @@ # Keep this file executable as-is in Python 3! # (Otherwise getting the version out of it from setup.py is impossible.) -from __future__ import absolute_import - import os import warnings from os import path diff --git a/sphinx/builders/devhelp.py b/sphinx/builders/devhelp.py index 13abf6b3be..1755b54eb7 100644 --- a/sphinx/builders/devhelp.py +++ b/sphinx/builders/devhelp.py @@ -10,7 +10,6 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from __future__ import absolute_import import gzip import re diff --git a/sphinx/builders/gettext.py b/sphinx/builders/gettext.py index d4407b305f..642c2be750 100644 --- a/sphinx/builders/gettext.py +++ b/sphinx/builders/gettext.py @@ -9,8 +9,6 @@ :license: BSD, see LICENSE for details. """ -from __future__ import unicode_literals - from codecs import open from collections import defaultdict, OrderedDict from datetime import datetime, tzinfo, timedelta diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py index 5695821ab5..c1e19e223f 100644 --- a/sphinx/cmd/quickstart.py +++ b/sphinx/cmd/quickstart.py @@ -8,7 +8,6 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from __future__ import absolute_import import argparse import locale diff --git a/sphinx/cmdline.py b/sphinx/cmdline.py index 545ae4e47a..7986071663 100644 --- a/sphinx/cmdline.py +++ b/sphinx/cmdline.py @@ -8,7 +8,6 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from __future__ import absolute_import import sys import warnings diff --git a/sphinx/ext/doctest.py b/sphinx/ext/doctest.py index 097550cd35..729abfea56 100644 --- a/sphinx/ext/doctest.py +++ b/sphinx/ext/doctest.py @@ -9,7 +9,6 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from __future__ import absolute_import import doctest import re diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index 3a89e60e5f..4c319a0718 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -8,7 +8,6 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from __future__ import absolute_import import fnmatch import os diff --git a/sphinx/util/compat.py b/sphinx/util/compat.py index e1af4612a4..144093ab42 100644 --- a/sphinx/util/compat.py +++ b/sphinx/util/compat.py @@ -9,8 +9,6 @@ :license: BSD, see LICENSE for details. """ -from __future__ import absolute_import - import sys import warnings diff --git a/sphinx/util/docfields.py b/sphinx/util/docfields.py index 885e5eb2d6..f6e07af744 100644 --- a/sphinx/util/docfields.py +++ b/sphinx/util/docfields.py @@ -9,7 +9,6 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from __future__ import absolute_import from typing import List, Tuple, cast diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py index 9e2ee740a1..db0ff5ed5f 100644 --- a/sphinx/util/docutils.py +++ b/sphinx/util/docutils.py @@ -8,7 +8,6 @@ :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 diff --git a/sphinx/util/fileutil.py b/sphinx/util/fileutil.py index ecce46c762..fae393d6d2 100644 --- a/sphinx/util/fileutil.py +++ b/sphinx/util/fileutil.py @@ -8,7 +8,6 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from __future__ import absolute_import import os import posixpath diff --git a/sphinx/util/images.py b/sphinx/util/images.py index 80ab52d3af..4c94af8812 100644 --- a/sphinx/util/images.py +++ b/sphinx/util/images.py @@ -8,7 +8,6 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from __future__ import absolute_import import base64 import imghdr diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 8a1181f1a6..ca7af28fa7 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -8,7 +8,6 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from __future__ import absolute_import import builtins import enum diff --git a/sphinx/util/logging.py b/sphinx/util/logging.py index b1fb050709..a82848921f 100644 --- a/sphinx/util/logging.py +++ b/sphinx/util/logging.py @@ -8,7 +8,6 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from __future__ import absolute_import import logging import logging.handlers diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py index e01c1490ff..568024a535 100644 --- a/sphinx/util/nodes.py +++ b/sphinx/util/nodes.py @@ -8,7 +8,6 @@ :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 Any, cast diff --git a/sphinx/util/parallel.py b/sphinx/util/parallel.py index d847fa1634..f71954d842 100644 --- a/sphinx/util/parallel.py +++ b/sphinx/util/parallel.py @@ -8,7 +8,6 @@ :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 diff --git a/sphinx/util/requests.py b/sphinx/util/requests.py index 3a3c2b6cb1..9c79f87361 100644 --- a/sphinx/util/requests.py +++ b/sphinx/util/requests.py @@ -9,8 +9,6 @@ :license: BSD, see LICENSE for details. """ -from __future__ import absolute_import - import warnings from contextlib import contextmanager from urllib.parse import urlsplit diff --git a/sphinx/util/rst.py b/sphinx/util/rst.py index 097e93c742..d3a1c41dff 100644 --- a/sphinx/util/rst.py +++ b/sphinx/util/rst.py @@ -8,7 +8,6 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from __future__ import absolute_import import re from contextlib import contextmanager diff --git a/sphinx/util/smartypants.py b/sphinx/util/smartypants.py index b4f2be0a04..e2e2ef2c0e 100644 --- a/sphinx/util/smartypants.py +++ b/sphinx/util/smartypants.py @@ -25,7 +25,6 @@ See the LICENSE file and the original docutils code for details. """ -from __future__ import absolute_import, unicode_literals import re diff --git a/sphinx/util/texescape.py b/sphinx/util/texescape.py index 4d5b9b1369..fa5055c0fb 100644 --- a/sphinx/util/texescape.py +++ b/sphinx/util/texescape.py @@ -9,8 +9,6 @@ :license: BSD, see LICENSE for details. """ -from __future__ import unicode_literals - if False: # For type annotation from typing import Dict # NOQA diff --git a/tests/roots/test-ext-autodoc/target/enum.py b/tests/roots/test-ext-autodoc/target/enum.py index 31e7c6ccdf..d0a59c71c7 100644 --- a/tests/roots/test-ext-autodoc/target/enum.py +++ b/tests/roots/test-ext-autodoc/target/enum.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import import enum diff --git a/tests/roots/test-ext-viewcode-find/not_a_package/__init__.py b/tests/roots/test-ext-viewcode-find/not_a_package/__init__.py index 4a1d689e5b..96e00169b8 100644 --- a/tests/roots/test-ext-viewcode-find/not_a_package/__init__.py +++ b/tests/roots/test-ext-viewcode-find/not_a_package/__init__.py @@ -1,3 +1,4 @@ +# TODO(stephenfin): Removing this breaks tests. Why? from __future__ import absolute_import from .submodule import func1, Class1 # NOQA diff --git a/tests/roots/test-ext-viewcode/spam/__init__.py b/tests/roots/test-ext-viewcode/spam/__init__.py index dffa85b914..2d5ca82399 100644 --- a/tests/roots/test-ext-viewcode/spam/__init__.py +++ b/tests/roots/test-ext-viewcode/spam/__init__.py @@ -1,4 +1,2 @@ -from __future__ import absolute_import - from .mod1 import func1, Class1 # NOQA from .mod2 import func2, Class2 # NOQA diff --git a/utils/bump_version.py b/utils/bump_version.py index 55da12551f..79a1fe6a7f 100755 --- a/utils/bump_version.py +++ b/utils/bump_version.py @@ -1,7 +1,5 @@ #!/usr/bin/env python -from __future__ import print_function - import argparse import os import re From 5a9033e5aa87bb9b58bdd622e7bd2c9361db03cf Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Fri, 5 Oct 2018 18:05:14 +0100 Subject: [PATCH 2/2] Specifically request Python 3 If Sphinx is Python 3-only, Sphinx's tooling should be Python 3-only too. Signed-off-by: Stephen Finucane --- tests/roots/test-apidoc-toc/mypackage/main.py | 3 ++- utils/bump_version.py | 2 +- utils/checks.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/roots/test-apidoc-toc/mypackage/main.py b/tests/roots/test-apidoc-toc/mypackage/main.py index b3fa386fc9..813db805eb 100755 --- a/tests/roots/test-apidoc-toc/mypackage/main.py +++ b/tests/roots/test-apidoc-toc/mypackage/main.py @@ -1,4 +1,5 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 + import os import mod_resource diff --git a/utils/bump_version.py b/utils/bump_version.py index 79a1fe6a7f..6491a38e30 100755 --- a/utils/bump_version.py +++ b/utils/bump_version.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import argparse import os diff --git a/utils/checks.py b/utils/checks.py index 3d421b385c..25b6b2fa82 100644 --- a/utils/checks.py +++ b/utils/checks.py @@ -60,7 +60,7 @@ def sphinx_has_header(physical_line, filename, lines, line_number): # line number correction offset = 1 - if lines[0:1] == ['#!/usr/bin/env python\n']: + if lines[0:1] == ['#!/usr/bin/env python3\n']: lines = lines[1:] offset = 2