Skip to content

Instantly share code, notes, and snippets.

@timothycrosley
Created October 2, 2020 06:11
Show Gist options
  • Save timothycrosley/ffa0362864b7f14feb3d136c6f3d6567 to your computer and use it in GitHub Desktop.
Save timothycrosley/ffa0362864b7f14feb3d136c6f3d6567 to your computer and use it in GitHub Desktop.
Diff produced from running isort on pytype
diff --git a/build_scripts/build.py b/build_scripts/build.py
index bff729f5..5659a569 100755
--- a/build_scripts/build.py
+++ b/build_scripts/build.py
@@ -15,6 +15,7 @@ import sys
import build_utils
import py27
+
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--clobber", "-c", action="store_true", default=False,
diff --git a/build_scripts/pyexe.py b/build_scripts/pyexe.py
index fee9df0e..3196f028 100644
--- a/build_scripts/pyexe.py
+++ b/build_scripts/pyexe.py
@@ -18,6 +18,7 @@ set to VALUE before calling the "main" function.
"""
from __future__ import print_function
+
import argparse
import os
import stat
diff --git a/build_scripts/release.py b/build_scripts/release.py
index 936c1128..b838e3f3 100644
--- a/build_scripts/release.py
+++ b/build_scripts/release.py
@@ -21,7 +21,6 @@ import shutil
import sys
import build_utils
-
from six.moves import input
TEST_MODE = "TEST"
diff --git a/build_scripts/run_cc_test.py b/build_scripts/run_cc_test.py
index 7a1c346b..72368e0d 100755
--- a/build_scripts/run_cc_test.py
+++ b/build_scripts/run_cc_test.py
@@ -16,6 +16,7 @@ import sys
import build_utils
+
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("-t", "--target", required=True, type=str,
diff --git a/build_scripts/run_tests.py b/build_scripts/run_tests.py
index ed862fc4..8edbfc6c 100755
--- a/build_scripts/run_tests.py
+++ b/build_scripts/run_tests.py
@@ -11,11 +11,13 @@ CMake files will be run.
"""
from __future__ import print_function
+
import argparse
import sys
import build_utils
+
def parse_args():
"""Parse the args to this script and return them."""
parser = argparse.ArgumentParser()
diff --git a/build_scripts/test_module.py b/build_scripts/test_module.py
index 43b29325..5ff2b44e 100755
--- a/build_scripts/test_module.py
+++ b/build_scripts/test_module.py
@@ -26,6 +26,7 @@ print flags (-p and -s).
"""
from __future__ import print_function
+
import argparse
import os
import sys
diff --git a/build_scripts/travis_script.py b/build_scripts/travis_script.py
index 33bf1fa8..78799704 100755
--- a/build_scripts/travis_script.py
+++ b/build_scripts/travis_script.py
@@ -9,7 +9,6 @@ import sys
import build_utils
-
STEP = collections.namedtuple("STEP", ["name", "command"])
diff --git a/pytype/__main__.py b/pytype/__main__.py
index 5a68fe8f..9b093eb1 100644
--- a/pytype/__main__.py
+++ b/pytype/__main__.py
@@ -5,6 +5,5 @@ import sys
from pytype.tools.analyze_project.main import main
-
if __name__ == '__main__':
sys.exit(main())
diff --git a/pytype/abstract_test.py b/pytype/abstract_test.py
index 48c577a2..8b6ff81a 100644
--- a/pytype/abstract_test.py
+++ b/pytype/abstract_test.py
@@ -1,5 +1,9 @@
"""Tests for abstract.py."""
+import unittest
+
+import six
+
from pytype import abstract
from pytype import abstract_utils
from pytype import config
@@ -13,9 +17,6 @@ from pytype.pytd import pytd
from pytype.pytd import pytd_utils
from pytype.tests import test_base
from pytype.typegraph import cfg
-import six
-
-import unittest
class AbstractTestBase(test_base.UnitTest):
diff --git a/pytype/abstract_utils_test.py b/pytype/abstract_utils_test.py
index 9b8fc73e..e7eedd36 100644
--- a/pytype/abstract_utils_test.py
+++ b/pytype/abstract_utils_test.py
@@ -1,5 +1,9 @@
"""Tests for abstract_utils.py."""
+import unittest
+
+import six
+
from pytype import abstract_utils
from pytype import config
from pytype import errors
@@ -7,10 +11,6 @@ from pytype import load_pytd
from pytype import vm
from pytype.tests import test_base
-import six
-
-import unittest
-
class GetViewsTest(test_base.UnitTest):
diff --git a/pytype/attribute_test.py b/pytype/attribute_test.py
index 07daace8..ef0904bf 100644
--- a/pytype/attribute_test.py
+++ b/pytype/attribute_test.py
@@ -1,5 +1,7 @@
"""Tests for attribute.py."""
+import unittest
+
from pytype import abstract
from pytype import abstract_utils
from pytype import config
@@ -8,8 +10,6 @@ from pytype import load_pytd
from pytype import vm
from pytype.tests import test_base
-import unittest
-
class AttributeTest(test_base.UnitTest):
diff --git a/pytype/blocks_test.py b/pytype/blocks_test.py
index 8e7388e1..87cbe68f 100644
--- a/pytype/blocks_test.py
+++ b/pytype/blocks_test.py
@@ -1,12 +1,13 @@
"""Tests for blocks.py."""
+import unittest
+
+import six
+
from pytype import blocks
from pytype.pyc import opcodes
from pytype.pyc import pyc
from pytype.tests import test_utils
-import six
-
-import unittest
class BaseBlocksTest(unittest.TestCase, test_utils.MakeCodeMixin):
diff --git a/pytype/collections_overlay_test.py b/pytype/collections_overlay_test.py
index 8ceeb6b7..d4a0da81 100644
--- a/pytype/collections_overlay_test.py
+++ b/pytype/collections_overlay_test.py
@@ -1,12 +1,12 @@
"""Tests for collections_overlay.py."""
+import unittest
+
from pytype.overlays import collections_overlay
from pytype.pytd import pytd
from pytype.pytd import pytd_utils
from pytype.tests import test_base
-import unittest
-
class NamedTupleAstTest(test_base.UnitTest):
"""Test collection_overlay's namedtuple AST generation."""
diff --git a/pytype/compare_test.py b/pytype/compare_test.py
index 0f7ad54f..7bb98899 100644
--- a/pytype/compare_test.py
+++ b/pytype/compare_test.py
@@ -1,5 +1,7 @@
"""Tests for compare.py."""
+import unittest
+
from pytype import abstract
from pytype import abstract_utils
from pytype import compare
@@ -12,8 +14,6 @@ from pytype.pytd import pytd
from pytype.pytd import slots
from pytype.tests import test_base
-import unittest
-
class CompareTestBase(test_base.UnitTest):
diff --git a/pytype/compat_test.py b/pytype/compat_test.py
index 419abe15..33f00723 100644
--- a/pytype/compat_test.py
+++ b/pytype/compat_test.py
@@ -1,12 +1,11 @@
"""Tests for compat.py."""
import os
+import unittest
from pytype import compat
from pytype import file_utils
-import unittest
-
class RecursiveGlobTest(unittest.TestCase):
"""Test recursive_glob()."""
diff --git a/pytype/config.py b/pytype/config.py
index edcac2e3..5ccf5735 100644
--- a/pytype/config.py
+++ b/pytype/config.py
@@ -17,7 +17,6 @@ from pytype import load_pytd
from pytype import utils
from pytype.typegraph import cfg_utils
-
LOG_LEVELS = [logging.CRITICAL, logging.ERROR, logging.WARNING, logging.INFO,
logging.DEBUG]
diff --git a/pytype/config_test.py b/pytype/config_test.py
index a936e140..91f75848 100644
--- a/pytype/config_test.py
+++ b/pytype/config_test.py
@@ -3,12 +3,11 @@
import logging
import sys
import types
+import unittest
from pytype import config
from pytype import utils
-import unittest
-
class ConfigTest(unittest.TestCase):
diff --git a/pytype/convert.py b/pytype/convert.py
index 8cec404b..224fdae1 100644
--- a/pytype/convert.py
+++ b/pytype/convert.py
@@ -20,7 +20,6 @@ from pytype.pytd import pytd
from pytype.pytd import pytd_utils
from pytype.typegraph import cfg
-
log = logging.getLogger(__name__)
diff --git a/pytype/convert_test.py b/pytype/convert_test.py
index 56202647..a54e7ed7 100644
--- a/pytype/convert_test.py
+++ b/pytype/convert_test.py
@@ -1,5 +1,9 @@
"""Tests for convert.py."""
+import unittest
+
+import six
+
from pytype import abstract
from pytype import abstract_utils
from pytype import config
@@ -10,9 +14,6 @@ from pytype import vm
from pytype.pytd import pytd
from pytype.pytd import pytd_utils
from pytype.tests import test_base
-import six
-
-import unittest
class ConvertTest(test_base.UnitTest):
diff --git a/pytype/datatypes_test.py b/pytype/datatypes_test.py
index 4548ddd9..e13f88eb 100644
--- a/pytype/datatypes_test.py
+++ b/pytype/datatypes_test.py
@@ -1,12 +1,11 @@
"""Tests for datatypes.py."""
import argparse
+import unittest
from pytype import datatypes
from pytype.typegraph import cfg
-import unittest
-
class AccessTrackingDictTest(unittest.TestCase):
"""Test AccessTrackingDict."""
diff --git a/pytype/debug.py b/pytype/debug.py
index 481b713e..4e6b38b9 100644
--- a/pytype/debug.py
+++ b/pytype/debug.py
@@ -4,11 +4,11 @@ import collections
import re
import traceback
+import six
+
from pytype import utils
from pytype.typegraph import cfg_utils
-import six
-
def _ascii_tree(io, node, p1, p2, seen, get_children, get_description=None):
"""Draw a graph, starting at a given position.
diff --git a/pytype/debug_test.py b/pytype/debug_test.py
index 6337a97b..cd07f771 100644
--- a/pytype/debug_test.py
+++ b/pytype/debug_test.py
@@ -1,12 +1,11 @@
"""Tests for utils.py."""
import textwrap
+import unittest
from pytype import debug
from pytype.typegraph import cfg
-import unittest
-
class Node:
"""A graph node, for testing tree printing."""
diff --git a/pytype/directors.py b/pytype/directors.py
index c7155441..44c3cb02 100644
--- a/pytype/directors.py
+++ b/pytype/directors.py
@@ -9,9 +9,10 @@ import re
import sys
import tokenize
+from six import moves
+
from pytype import blocks
from pytype import utils
-from six import moves
log = logging.getLogger(__name__)
diff --git a/pytype/directors_test.py b/pytype/directors_test.py
index 2f8d8fe8..7d85139f 100644
--- a/pytype/directors_test.py
+++ b/pytype/directors_test.py
@@ -2,12 +2,13 @@
"""Tests for directors.py."""
import sys
+import unittest
+
+import six
from pytype import directors
from pytype import errors
from pytype.tests import test_utils
-import six
-import unittest
_TEST_FILENAME = "my_file.py"
diff --git a/pytype/errors.py b/pytype/errors.py
index 990a5075..433347a0 100644
--- a/pytype/errors.py
+++ b/pytype/errors.py
@@ -8,6 +8,8 @@ import re
import sys
from typing import Iterable, Optional, Union
+import six
+
from pytype import abstract
from pytype import debug
from pytype import function
@@ -17,7 +19,6 @@ from pytype.pytd import optimize
from pytype.pytd import pytd_utils
from pytype.pytd import slots
from pytype.pytd import visitors
-import six
# Usually we call the logger "log" but that name is used quite often here.
_log = logging.getLogger(__name__)
diff --git a/pytype/errors_test.py b/pytype/errors_test.py
index a54ffec2..b27e2f23 100644
--- a/pytype/errors_test.py
+++ b/pytype/errors_test.py
@@ -4,14 +4,13 @@ import collections
import csv
import os
import textwrap
+import unittest
from pytype import errors
from pytype import file_utils
from pytype import state as frame_state
from pytype.tests import test_utils
-import unittest
-
_TEST_ERROR = "test-error"
_MESSAGE = "an error message on 'here'"
diff --git a/pytype/file_utils_test.py b/pytype/file_utils_test.py
index 8f7d7c60..2fec7f42 100644
--- a/pytype/file_utils_test.py
+++ b/pytype/file_utils_test.py
@@ -1,11 +1,11 @@
"""Tests for file_utils.py."""
import os
+import unittest
-from pytype import file_utils
import six
-import unittest
+from pytype import file_utils
class FileUtilsTest(unittest.TestCase):
diff --git a/pytype/imports_map_loader_test.py b/pytype/imports_map_loader_test.py
index f534ad95..d1588bd6 100644
--- a/pytype/imports_map_loader_test.py
+++ b/pytype/imports_map_loader_test.py
@@ -3,15 +3,14 @@
import os
import tempfile
import textwrap
+import unittest
+
+import six
from pytype import compat
from pytype import file_utils
from pytype import imports_map_loader
-import six
-
-import unittest
-
class ImportMapLoaderTest(unittest.TestCase):
"""Tests for imports_map_loader.py."""
diff --git a/pytype/io.py b/pytype/io.py
index e61577e5..507b8349 100644
--- a/pytype/io.py
+++ b/pytype/io.py
@@ -7,6 +7,8 @@ import sys
import tokenize
import traceback
+import six
+
from pytype import __version__
from pytype import analyze
from pytype import config
@@ -22,9 +24,6 @@ from pytype.pytd import serialize_ast
from pytype.pytd import visitors
from pytype.pytd.parse import builtins as pytd_builtins
-import six
-
-
log = logging.getLogger(__name__)
diff --git a/pytype/io_test.py b/pytype/io_test.py
index d63149e2..5cda4c86 100644
--- a/pytype/io_test.py
+++ b/pytype/io_test.py
@@ -6,13 +6,13 @@ import os
import sys
import tempfile
import traceback
+import unittest
+
+import six
from pytype import config
from pytype import io
from pytype.pytd import pytd
-import six
-
-import unittest
class IOTest(unittest.TestCase):
diff --git a/pytype/load_pytd.py b/pytype/load_pytd.py
index 487721db..fd585fc1 100644
--- a/pytype/load_pytd.py
+++ b/pytype/load_pytd.py
@@ -4,6 +4,8 @@ import collections
import logging
import os
+from six.moves import cPickle
+
from pytype import file_utils
from pytype import module_utils
from pytype import utils
@@ -14,7 +16,6 @@ from pytype.pytd import serialize_ast
from pytype.pytd import typeshed
from pytype.pytd import visitors
from pytype.pytd.parse import builtins
-from six.moves import cPickle
log = logging.getLogger(__name__)
diff --git a/pytype/load_pytd_test.py b/pytype/load_pytd_test.py
index 1d312b9c..9e60fde6 100644
--- a/pytype/load_pytd_test.py
+++ b/pytype/load_pytd_test.py
@@ -4,6 +4,7 @@ import collections
import io
import os
import textwrap
+import unittest
from pytype import file_utils
from pytype import load_pytd
@@ -13,8 +14,6 @@ from pytype.pytd import serialize_ast
from pytype.pytd import visitors
from pytype.tests import test_base
-import unittest
-
class ImportPathsTest(test_base.UnitTest):
"""Tests for load_pytd.py."""
diff --git a/pytype/matcher.py b/pytype/matcher.py
index 0685fc66..1a4b4111 100644
--- a/pytype/matcher.py
+++ b/pytype/matcher.py
@@ -18,7 +18,6 @@ from pytype.pytd import pytd
from pytype.pytd import pytd_utils
from pytype.pytd.parse import parser_constants
-
log = logging.getLogger(__name__)
diff --git a/pytype/matcher_test.py b/pytype/matcher_test.py
index 28d450ed..07ea13c2 100644
--- a/pytype/matcher_test.py
+++ b/pytype/matcher_test.py
@@ -1,5 +1,9 @@
"""Tests for matcher.py."""
+import unittest
+
+import six
+
from pytype import abstract
from pytype import abstract_utils
from pytype import config
@@ -9,10 +13,6 @@ from pytype import load_pytd
from pytype import vm
from pytype.tests import test_base
-import six
-
-import unittest
-
class MatcherTest(test_base.UnitTest):
"""Test matcher.AbstractMatcher."""
diff --git a/pytype/metrics.py b/pytype/metrics.py
index 20cbecb8..effdeb2c 100644
--- a/pytype/metrics.py
+++ b/pytype/metrics.py
@@ -26,7 +26,6 @@ import time
import six
-
# TODO(tsudol): Not needed once pytype is ported to Python 3.
try:
import tracemalloc # pytype: disable=import-error # pylint: disable=g-import-not-at-top
diff --git a/pytype/metrics_test.py b/pytype/metrics_test.py
index 849c26f8..5bde03e5 100644
--- a/pytype/metrics_test.py
+++ b/pytype/metrics_test.py
@@ -4,11 +4,10 @@ import io
import math
import tempfile
import time
+import unittest
from pytype import metrics
-import unittest
-
class MetricsTest(unittest.TestCase):
"""Tests for metrics infrastructure and the Counter class."""
diff --git a/pytype/mixin.py b/pytype/mixin.py
index 3ae0b84e..de02d900 100644
--- a/pytype/mixin.py
+++ b/pytype/mixin.py
@@ -2,14 +2,14 @@
import logging
+import six
+
from pytype import abstract_utils
from pytype import datatypes
from pytype import function
from pytype.pytd import mro
from pytype.pytd import pytd
-import six
-
log = logging.getLogger(__name__)
diff --git a/pytype/mixin_test.py b/pytype/mixin_test.py
index 12843523..dad9c76d 100644
--- a/pytype/mixin_test.py
+++ b/pytype/mixin_test.py
@@ -1,9 +1,11 @@
"""Tests for mixin.py."""
-from pytype import mixin
-import six
import unittest
+import six
+
+from pytype import mixin
+
class MixinMetaTest(unittest.TestCase):
diff --git a/pytype/module_utils_test.py b/pytype/module_utils_test.py
index 2eddb7e4..68b4a838 100644
--- a/pytype/module_utils_test.py
+++ b/pytype/module_utils_test.py
@@ -1,12 +1,11 @@
"""Tests for module_utils.py."""
import os
+import unittest
from pytype import file_utils
from pytype import module_utils
-import unittest
-
class ModuleUtilsTest(unittest.TestCase):
"""Test module utilities."""
diff --git a/pytype/output.py b/pytype/output.py
index 3eef361c..df48f79b 100644
--- a/pytype/output.py
+++ b/pytype/output.py
@@ -4,6 +4,8 @@ import collections
import contextlib
import logging
+from six import moves
+
from pytype import abstract
from pytype import abstract_utils
from pytype import mixin
@@ -14,7 +16,6 @@ from pytype.overlays import typing_overlay
from pytype.pytd import pytd
from pytype.pytd import pytd_utils
from pytype.pytd import visitors
-from six import moves
log = logging.getLogger(__name__)
diff --git a/pytype/overlay_utils.py b/pytype/overlay_utils.py
index 86cf3cc3..79e6e631 100644
--- a/pytype/overlay_utils.py
+++ b/pytype/overlay_utils.py
@@ -4,7 +4,6 @@ from pytype import abstract
from pytype import mixin
from pytype.typegraph import cfg
-
# Various types accepted by the annotations dictionary.
# Runtime type checking of annotations, since if we do have an unexpected type
# being stored in annotations, we should catch that as soon as possible, and add
diff --git a/pytype/overlays/classgen.py b/pytype/overlays/classgen.py
index bda57c1c..5b735dfd 100644
--- a/pytype/overlays/classgen.py
+++ b/pytype/overlays/classgen.py
@@ -13,7 +13,6 @@ from pytype import mixin
from pytype import overlay_utils
from pytype import special_builtins
-
log = logging.getLogger(__name__)
diff --git a/pytype/overlays/typing_overlay.py b/pytype/overlays/typing_overlay.py
index 86ed1e0a..0420d107 100644
--- a/pytype/overlays/typing_overlay.py
+++ b/pytype/overlays/typing_overlay.py
@@ -3,6 +3,8 @@
# pylint's detection of this is error-prone:
# pylint: disable=unpacking-non-sequence
+from six import moves
+
from pytype import abstract
from pytype import abstract_utils
from pytype import compat
@@ -15,8 +17,6 @@ from pytype.overlays import collections_overlay
from pytype.pytd import pep484
from pytype.pytd import pytd
from pytype.pytd import visitors
-from six import moves
-
# type alias
Param = overlay_utils.Param
diff --git a/pytype/pyc/loadmarshal.py b/pytype/pyc/loadmarshal.py
index df0f18b5..b74665e2 100644
--- a/pytype/pyc/loadmarshal.py
+++ b/pytype/pyc/loadmarshal.py
@@ -13,10 +13,10 @@ import contextlib
import struct
import sys
-from pytype import compat
import six
import six.moves
+from pytype import compat
TYPE_NULL = 0x30 # '0'
TYPE_NONE = 0x4e # 'N'
diff --git a/pytype/pyc/loadmarshal_test.py b/pytype/pyc/loadmarshal_test.py
index f516a192..9d67c807 100644
--- a/pytype/pyc/loadmarshal_test.py
+++ b/pytype/pyc/loadmarshal_test.py
@@ -1,10 +1,10 @@
"""Tests for loadmarshal.py."""
import sys
+import unittest
from pytype import compat
from pytype.pyc import loadmarshal
-import unittest
class TestLoadMarshal(unittest.TestCase):
diff --git a/pytype/pyc/magic_test.py b/pytype/pyc/magic_test.py
index e512b0e5..ae00fe93 100644
--- a/pytype/pyc/magic_test.py
+++ b/pytype/pyc/magic_test.py
@@ -1,8 +1,9 @@
"""Tests for magic.py."""
-from pytype.pyc import magic
import unittest
+from pytype.pyc import magic
+
class TestMagic(unittest.TestCase):
"""Tests for the functions in magic.py."""
diff --git a/pytype/pyc/opcodes_test.py b/pytype/pyc/opcodes_test.py
index c1e8071d..048c402e 100644
--- a/pytype/pyc/opcodes_test.py
+++ b/pytype/pyc/opcodes_test.py
@@ -1,6 +1,7 @@
+import unittest
+
from pytype import compat
from pytype.pyc import opcodes
-import unittest
class _TestBase(unittest.TestCase):
diff --git a/pytype/pyc/pyc.py b/pytype/pyc/pyc.py
index acb6f66b..7fec050d 100644
--- a/pytype/pyc/pyc.py
+++ b/pytype/pyc/pyc.py
@@ -7,14 +7,14 @@ import subprocess
import tempfile
from typing import List, Tuple
+import six
+
from pytype import compat
from pytype import pytype_source_utils
from pytype import utils
from pytype.pyc import compile_bytecode
from pytype.pyc import loadmarshal
from pytype.pyc import magic
-import six
-
COMPILE_SCRIPT = "pyc/compile_bytecode.py"
COMPILE_ERROR_RE = re.compile(r"^(.*) \((.*), line (\d+)\)$")
diff --git a/pytype/pyc/pyc_test.py b/pytype/pyc/pyc_test.py
index 46fb77a3..789f41ec 100644
--- a/pytype/pyc/pyc_test.py
+++ b/pytype/pyc/pyc_test.py
@@ -1,11 +1,13 @@
# coding=utf8
"""Tests for pyc.py."""
+import unittest
+
+import six
+
from pytype.pyc import opcodes
from pytype.pyc import pyc
from pytype.tests import test_base
-import six
-import unittest
class TestCompileError(unittest.TestCase):
diff --git a/pytype/pyi/lexer_test.py b/pytype/pyi/lexer_test.py
index 77b85b55..503940f7 100644
--- a/pytype/pyi/lexer_test.py
+++ b/pytype/pyi/lexer_test.py
@@ -1,12 +1,11 @@
import os
import textwrap
+import unittest
from pytype.pyi import parser_ext
from pytype.pytd.parse import parser_constants
from pytype.tests import test_base
-import unittest
-
# Map from token code to name.
TOKEN_NAMES = {code: name for name, code in parser_ext.TOKENS.items()}
diff --git a/pytype/pyi/parser.py b/pytype/pyi/parser.py
index 095d3d73..68963c92 100644
--- a/pytype/pyi/parser.py
+++ b/pytype/pyi/parser.py
@@ -12,7 +12,8 @@ from pytype.pytd import pytd
from pytype.pytd import pytd_utils
from pytype.pytd import slots as cmp_slots
from pytype.pytd import visitors
-from pytype.pytd.parse import parser_constants # pylint: disable=g-importing-member
+from pytype.pytd.parse import \
+ parser_constants # pylint: disable=g-importing-member
_DEFAULT_PLATFORM = "linux"
# Typing members that represent sets of types.
diff --git a/pytype/pyi/parser_memleak_test.py b/pytype/pyi/parser_memleak_test.py
index 262694ea..261a7c46 100644
--- a/pytype/pyi/parser_memleak_test.py
+++ b/pytype/pyi/parser_memleak_test.py
@@ -1,13 +1,13 @@
import gc
import os
import sys
+import unittest
+
+import six
from pytype.pyi import parser
from pytype.pytd import pytd
from pytype.tests import test_base
-import six
-
-import unittest
def get_builtins_source(python_version):
diff --git a/pytype/pyi/parser_test.py b/pytype/pyi/parser_test.py
index e8dc8e1f..6a36eff1 100644
--- a/pytype/pyi/parser_test.py
+++ b/pytype/pyi/parser_test.py
@@ -2,15 +2,15 @@ import hashlib
import os
import re
import textwrap
+import unittest
+
+import six
from pytype import utils
from pytype.pyi import parser
from pytype.pytd import pytd
from pytype.pytd import pytd_utils
from pytype.tests import test_base
-import six
-
-import unittest
IGNORE = object()
diff --git a/pytype/pytd/abc_hierarchy.py b/pytype/pytd/abc_hierarchy.py
index 64aacf29..ba12522c 100644
--- a/pytype/pytd/abc_hierarchy.py
+++ b/pytype/pytd/abc_hierarchy.py
@@ -2,7 +2,6 @@
from pytype import utils
-
# (We specify the below manually, instead of extracting it out of abc.py,
# because we need support for Python 2 as well as Python 3 without having to
# depend on the "host" Python)
diff --git a/pytype/pytd/abc_hierarchy_test.py b/pytype/pytd/abc_hierarchy_test.py
index bb31f55a..e9342202 100644
--- a/pytype/pytd/abc_hierarchy_test.py
+++ b/pytype/pytd/abc_hierarchy_test.py
@@ -1,8 +1,9 @@
"""Tests for abc_hierarchy.py."""
-from pytype.pytd import abc_hierarchy
import unittest
+from pytype.pytd import abc_hierarchy
+
class TestAbcHierarchy(unittest.TestCase):
"""Test abc_hierarchy.py."""
diff --git a/pytype/pytd/booleq_test.py b/pytype/pytd/booleq_test.py
index 97fe7987..a57ba5ae 100644
--- a/pytype/pytd/booleq_test.py
+++ b/pytype/pytd/booleq_test.py
@@ -1,9 +1,10 @@
"""Tests for booleq.py."""
-from pytype.pytd import booleq
-import six
import unittest
+import six
+
+from pytype.pytd import booleq
# pylint: disable=invalid-name
And = booleq.And
diff --git a/pytype/pytd/main_test.py b/pytype/pytd/main_test.py
index 5e62a877..2322891d 100644
--- a/pytype/pytd/main_test.py
+++ b/pytype/pytd/main_test.py
@@ -3,9 +3,10 @@
import os
import sys
import textwrap
+import unittest
+
from pytype import file_utils
from pytype.pytd import main as pytd_tool
-import unittest
class TestPytdTool(unittest.TestCase):
diff --git a/pytype/pytd/mro_test.py b/pytype/pytd/mro_test.py
index 0cc83cb7..9e06e70f 100644
--- a/pytype/pytd/mro_test.py
+++ b/pytype/pytd/mro_test.py
@@ -1,11 +1,11 @@
import textwrap
+import unittest
from pytype import load_pytd
from pytype.pyi import parser
from pytype.pytd import mro
from pytype.pytd import visitors
from pytype.pytd.parse import parser_test_base
-import unittest
class MroTest(parser_test_base.ParserTest):
diff --git a/pytype/pytd/optimize.py b/pytype/pytd/optimize.py
index 814207c3..145a5d1f 100644
--- a/pytype/pytd/optimize.py
+++ b/pytype/pytd/optimize.py
@@ -9,6 +9,8 @@
import collections
import logging
+import six
+
from pytype import utils
from pytype.pytd import abc_hierarchy
from pytype.pytd import booleq
@@ -16,7 +18,6 @@ from pytype.pytd import pytd
from pytype.pytd import pytd_utils
from pytype.pytd import type_match
from pytype.pytd import visitors
-import six
log = logging.getLogger(__name__)
diff --git a/pytype/pytd/optimize_test.py b/pytype/pytd/optimize_test.py
index 710cf88e..864d8c05 100644
--- a/pytype/pytd/optimize_test.py
+++ b/pytype/pytd/optimize_test.py
@@ -1,4 +1,5 @@
import textwrap
+import unittest
from pytype import load_pytd
from pytype.pytd import optimize
@@ -6,7 +7,6 @@ from pytype.pytd import pytd
from pytype.pytd import pytd_utils
from pytype.pytd import visitors
from pytype.pytd.parse import parser_test_base
-import unittest
class TestOptimize(parser_test_base.ParserTest):
diff --git a/pytype/pytd/parse/builtins_test.py b/pytype/pytd/parse/builtins_test.py
index affef204..0714110a 100644
--- a/pytype/pytd/parse/builtins_test.py
+++ b/pytype/pytd/parse/builtins_test.py
@@ -1,10 +1,11 @@
"""Tests for pytype.pytd.parse.builtins."""
+import unittest
+
from pytype.pytd import pytd
from pytype.pytd import visitors
from pytype.pytd.parse import builtins
from pytype.tests import test_base
-import unittest
class UtilsTest(test_base.UnitTest):
diff --git a/pytype/pytd/parse/node.py b/pytype/pytd/parse/node.py
index 9b5afa1c..a79d9b0e 100644
--- a/pytype/pytd/parse/node.py
+++ b/pytype/pytd/parse/node.py
@@ -49,7 +49,6 @@ import collections
from pytype import metrics
from pytype.pytd.parse import preconditions
-
_CHECK_PRECONDITIONS = None
diff --git a/pytype/pytd/parse/node_test.py b/pytype/pytd/parse/node_test.py
index 01b91425..608fb5b5 100644
--- a/pytype/pytd/parse/node_test.py
+++ b/pytype/pytd/parse/node_test.py
@@ -1,9 +1,8 @@
import itertools
+import unittest
from pytype.pytd import visitors
from pytype.pytd.parse import node
-import unittest
-
# gpylint doesn't understand collections.namedtuple():
# pylint: disable=no-member
diff --git a/pytype/pytd/parse/preconditions_test.py b/pytype/pytd/parse/preconditions_test.py
index bcb8a91f..97d2a0e3 100644
--- a/pytype/pytd/parse/preconditions_test.py
+++ b/pytype/pytd/parse/preconditions_test.py
@@ -1,7 +1,8 @@
-from pytype.pytd.parse import preconditions
+import unittest
+
import six
-import unittest
+from pytype.pytd.parse import preconditions
class BaseClass:
diff --git a/pytype/pytd/pep484.py b/pytype/pytd/pep484.py
index 8a3a42ba..bcc4ab20 100644
--- a/pytype/pytd/pep484.py
+++ b/pytype/pytd/pep484.py
@@ -3,7 +3,6 @@
from pytype.pytd import pytd
from pytype.pytd import visitors
-
PEP484_NAMES = ["AbstractSet", "AnyStr", "AsyncGenerator", "BinaryIO",
"ByteString", "Callable", "Container", "Dict", "FrozenSet",
"Generator", "Generic", "Hashable", "IO", "ItemsView",
diff --git a/pytype/pytd/pep484_test.py b/pytype/pytd/pep484_test.py
index eec203ca..9b4c90c2 100644
--- a/pytype/pytd/pep484_test.py
+++ b/pytype/pytd/pep484_test.py
@@ -1,8 +1,9 @@
+import unittest
+
from pytype.pytd import pep484
from pytype.pytd import pytd
from pytype.pytd import pytd_utils
from pytype.pytd.parse import parser_test_base
-import unittest
class TestPEP484(parser_test_base.ParserTest):
diff --git a/pytype/pytd/pytd.py b/pytype/pytd/pytd.py
index 29642fdc..314bf790 100644
--- a/pytype/pytd/pytd.py
+++ b/pytype/pytd/pytd.py
@@ -6,7 +6,6 @@ import itertools
from pytype.pytd.parse import node
from pytype.pytd.parse import preconditions
-
# This mixin is used to define the classes that satisfy the {Type}
# precondition. Each type class below should inherit from this mixin.
# Note that the mixin must be registered with preconditions.register() below.
diff --git a/pytype/pytd/pytd_test.py b/pytype/pytd/pytd_test.py
index 039161b3..dec36264 100644
--- a/pytype/pytd/pytd_test.py
+++ b/pytype/pytd/pytd_test.py
@@ -2,10 +2,11 @@
import itertools
import pickle
+import unittest
-from pytype.pytd import pytd
from six.moves import cPickle
-import unittest
+
+from pytype.pytd import pytd
class TestPytd(unittest.TestCase):
diff --git a/pytype/pytd/pytd_utils.py b/pytype/pytd/pytd_utils.py
index 44e31a3f..9a5161e1 100644
--- a/pytype/pytd/pytd_utils.py
+++ b/pytype/pytd/pytd_utils.py
@@ -16,13 +16,13 @@ import pickletools
import re
import sys
+import six
+from six.moves import cPickle
+
from pytype import pytype_source_utils
from pytype import utils
from pytype.pytd import pytd
from pytype.pytd import pytd_visitors
-import six
-from six.moves import cPickle
-
_PICKLE_PROTOCOL = cPickle.HIGHEST_PROTOCOL
_PICKLE_RECURSION_LIMIT_AST = 40000
diff --git a/pytype/pytd/pytd_utils_test.py b/pytype/pytd/pytd_utils_test.py
index f17f84a5..8c305730 100644
--- a/pytype/pytd/pytd_utils_test.py
+++ b/pytype/pytd/pytd_utils_test.py
@@ -1,5 +1,8 @@
import os
import textwrap
+import unittest
+
+import six
from pytype import file_utils
from pytype.pyi import parser
@@ -9,9 +12,6 @@ from pytype.pytd import serialize_ast
from pytype.pytd import visitors
from pytype.pytd.parse import parser_test_base
-import six
-import unittest
-
class TestUtils(parser_test_base.ParserTest):
"""Test pytype.pytd.pytd_utils."""
diff --git a/pytype/pytd/pytd_visitors.py b/pytype/pytd/pytd_visitors.py
index b1e1408d..7aad8745 100644
--- a/pytype/pytd/pytd_visitors.py
+++ b/pytype/pytd/pytd_visitors.py
@@ -12,7 +12,6 @@ from pytype.pytd import pytd
from pytype.pytd.parse import parser_constants
from pytype.typegraph import cfg_utils
-
# A convenient value for unchecked_node_classnames if a visitor wants to
# use unchecked nodes everywhere.
ALL_NODE_NAMES = type(
diff --git a/pytype/pytd/pytd_visitors_test.py b/pytype/pytd/pytd_visitors_test.py
index 27471353..1bd191a3 100644
--- a/pytype/pytd/pytd_visitors_test.py
+++ b/pytype/pytd/pytd_visitors_test.py
@@ -1,13 +1,13 @@
"""Tests for pytd_visitors."""
import textwrap
+import unittest
+
+import six
from pytype.pytd import pytd_visitors
from pytype.pytd import visitors
from pytype.pytd.parse import parser_test_base
-import six
-
-import unittest
class PytdVisitorsTest(parser_test_base.ParserTest):
diff --git a/pytype/pytd/serialize_ast_test.py b/pytype/pytd/serialize_ast_test.py
index 556e7624..86d6a7af 100644
--- a/pytype/pytd/serialize_ast_test.py
+++ b/pytype/pytd/serialize_ast_test.py
@@ -1,5 +1,8 @@
import os
import pickle
+import unittest
+
+import six
from pytype import file_utils
from pytype import load_pytd
@@ -7,9 +10,6 @@ from pytype.pytd import pytd_utils
from pytype.pytd import serialize_ast
from pytype.pytd import visitors
from pytype.tests import test_base
-import six
-
-import unittest
class SerializeAstTest(test_base.UnitTest):
diff --git a/pytype/pytd/slots_test.py b/pytype/pytd/slots_test.py
index c6802cd5..cd0d61c1 100644
--- a/pytype/pytd/slots_test.py
+++ b/pytype/pytd/slots_test.py
@@ -1,8 +1,9 @@
"""Tests for slots.py."""
-from pytype.pytd import slots
import unittest
+from pytype.pytd import slots
+
class TestPytd(unittest.TestCase):
"""Test the operator mappings in slots.py."""
diff --git a/pytype/pytd/transforms_test.py b/pytype/pytd/transforms_test.py
index a11ac677..484e6416 100644
--- a/pytype/pytd/transforms_test.py
+++ b/pytype/pytd/transforms_test.py
@@ -1,10 +1,10 @@
"""Tests for transforms.py."""
import textwrap
+import unittest
from pytype.pytd import transforms
from pytype.pytd.parse import parser_test_base
-import unittest
class TestTransforms(parser_test_base.ParserTest):
diff --git a/pytype/pytd/type_match_test.py b/pytype/pytd/type_match_test.py
index 156a5872..a59679fc 100644
--- a/pytype/pytd/type_match_test.py
+++ b/pytype/pytd/type_match_test.py
@@ -1,6 +1,7 @@
"""Tests for type_match.py."""
import textwrap
+import unittest
from pytype.pyi import parser
from pytype.pytd import booleq
@@ -10,9 +11,6 @@ from pytype.pytd import type_match
from pytype.pytd import visitors
from pytype.pytd.parse import parser_test_base
-import unittest
-
-
_BUILTINS = """
class object: ...
class classobj: ...
diff --git a/pytype/pytd/visitors.py b/pytype/pytd/visitors.py
index b3ef13e2..eddd5fd1 100644
--- a/pytype/pytd/visitors.py
+++ b/pytype/pytd/visitors.py
@@ -15,7 +15,8 @@ from pytype.pytd import mro
from pytype.pytd import pytd
from pytype.pytd import pytd_utils
from pytype.pytd import pytd_visitors
-from pytype.pytd.parse import parser_constants # pylint: disable=g-importing-member
+from pytype.pytd.parse import \
+ parser_constants # pylint: disable=g-importing-member
class ContainerError(Exception):
diff --git a/pytype/pytd/visitors_test.py b/pytype/pytd/visitors_test.py
index f3a5f724..6d4e03b1 100644
--- a/pytype/pytd/visitors_test.py
+++ b/pytype/pytd/visitors_test.py
@@ -1,13 +1,12 @@
import textwrap
+import unittest
+
+import six
from pytype.pytd import pytd
from pytype.pytd import pytd_utils
from pytype.pytd import visitors
from pytype.pytd.parse import parser_test_base
-import six
-
-import unittest
-
# All of these tests implicitly test pytd_utils.Print because
# parser_test_base.AssertSourceEquals() uses pytd_utils.Print.
diff --git a/pytype/pytype_source_utils_test.py b/pytype/pytype_source_utils_test.py
index 39098551..a3fb6c69 100644
--- a/pytype/pytype_source_utils_test.py
+++ b/pytype/pytype_source_utils_test.py
@@ -2,12 +2,11 @@
import os
import sys
+import unittest
from pytype import pytype_source_utils
from pytype import utils
-import unittest
-
class PytypeSourceUtilsTest(unittest.TestCase):
"""Test pytype source utilities."""
diff --git a/pytype/single.py b/pytype/single.py
index 83a42b22..96e910be 100755
--- a/pytype/single.py
+++ b/pytype/single.py
@@ -19,7 +19,6 @@ from pytype import utils
from pytype.pytd import typeshed
from pytype.pytd.parse import node
-
log = logging.getLogger(__name__)
diff --git a/pytype/single_test.py b/pytype/single_test.py
index 7d40c420..725566e0 100644
--- a/pytype/single_test.py
+++ b/pytype/single_test.py
@@ -8,6 +8,7 @@ import subprocess
import sys
import tempfile
import textwrap
+import unittest
from pytype import config
from pytype import single
@@ -17,7 +18,6 @@ from pytype.pytd import pytd_utils
from pytype.pytd import typeshed
from pytype.pytd.parse import builtins
from pytype.tests import test_base
-import unittest
class PytypeTest(test_base.UnitTest):
diff --git a/pytype/state_test.py b/pytype/state_test.py
index 495ee6b3..cbc01aa7 100644
--- a/pytype/state_test.py
+++ b/pytype/state_test.py
@@ -1,11 +1,11 @@
"""Test state.py."""
+import unittest
+
from pytype import compare
from pytype import state
from pytype.typegraph import cfg
-import unittest
-
def source_summary(binding, **varnames):
"""A simple deterministic listing of source variables."""
diff --git a/pytype/test_data/async_iter.py b/pytype/test_data/async_iter.py
index 00b15091..b73522d2 100644
--- a/pytype/test_data/async_iter.py
+++ b/pytype/test_data/async_iter.py
@@ -5,6 +5,7 @@
# YIELD_FROM
import asyncio
+
class AsyncIterable:
def __aiter__(self):
return self
diff --git a/pytype/test_data/pytree.py b/pytype/test_data/pytree.py
index dd720486..7bfccf10 100644
--- a/pytype/test_data/pytree.py
+++ b/pytype/test_data/pytree.py
@@ -20,8 +20,9 @@ _type_reprs = {} # Used by type_repr
def type_repr(type_num):
"""Map a type number to its string representation."""
if not _type_reprs:
- from lib2to3.pygram import python_symbols
from lib2to3.pgen2 import token
+ from lib2to3.pygram import python_symbols
+
# Fill in _type_reprs mappings from the symbols and tokens to strings.
# Requires that the symbols and tokens have disjoint numeric ranges ...
# they're partitioned at 256 (see comment for Symbols in pygram.py).
diff --git a/pytype/tests/test_base.py b/pytype/tests/test_base.py
index a9b01419..ebf5715c 100644
--- a/pytype/tests/test_base.py
+++ b/pytype/tests/test_base.py
@@ -4,6 +4,9 @@ import logging
import re
import sys
import textwrap
+import unittest
+
+import six
from pytype import analyze
from pytype import config
@@ -17,9 +20,6 @@ from pytype.pytd import pytd_utils
from pytype.pytd import serialize_ast
from pytype.pytd import visitors
from pytype.tests import test_utils
-import six
-
-import unittest
log = logging.getLogger(__name__)
diff --git a/pytype/tests/test_base_test.py b/pytype/tests/test_base_test.py
index fdec5a60..6ba99a67 100644
--- a/pytype/tests/test_base_test.py
+++ b/pytype/tests/test_base_test.py
@@ -1,10 +1,11 @@
"""Tests for our test framework."""
+import six
+
from pytype import file_utils
from pytype import utils
from pytype.tests import test_base
from pytype.tests import test_utils
-import six
class ErrorLogTest(test_base.TargetIndependentTest):
diff --git a/pytype/tests/test_pickle.py b/pytype/tests/test_pickle.py
index 2565a067..3022ab76 100644
--- a/pytype/tests/test_pickle.py
+++ b/pytype/tests/test_pickle.py
@@ -2,14 +2,14 @@
import textwrap
+import six
+from six.moves import cPickle
+
from pytype import file_utils
from pytype.pyi import parser
from pytype.pytd import visitors
from pytype.tests import test_base
-import six
-from six.moves import cPickle
-
class PickleTest(test_base.TargetIndependentTest):
"""Tests for loading and saving pickled files."""
diff --git a/pytype/tests/test_utils.py b/pytype/tests/test_utils.py
index 48a18e77..dc84de1a 100644
--- a/pytype/tests/test_utils.py
+++ b/pytype/tests/test_utils.py
@@ -6,17 +6,15 @@ import itertools
import re
import sys
import tokenize
+import unittest
+
+import six
from pytype import compat
from pytype import errors
from pytype import state as frame_state
from pytype.pyc import loadmarshal
-import six
-
-import unittest
-
-
# Pytype offers a Python 2.7 interpreter with type annotations backported as a
# __future__ import (see pytype/patches/python_2_7_type_annotations.diff).
ANNOTATIONS_IMPORT = "from __future__ import google_type_annotations"
diff --git a/pytype/tools/analyze_project/config.py b/pytype/tools/analyze_project/config.py
index 8584f05b..b7210ea5 100644
--- a/pytype/tools/analyze_project/config.py
+++ b/pytype/tools/analyze_project/config.py
@@ -10,7 +10,6 @@ from pytype import file_utils
from pytype import utils
from pytype.tools import config
-
# A config item.
# Args:
# default: the default value.
diff --git a/pytype/tools/analyze_project/config_test.py b/pytype/tools/analyze_project/config_test.py
index ef746c8f..e20c2db4 100644
--- a/pytype/tools/analyze_project/config_test.py
+++ b/pytype/tools/analyze_project/config_test.py
@@ -3,12 +3,11 @@
import os
import sys
import types
+import unittest
from pytype import file_utils
from pytype.tools.analyze_project import config
from pytype.tools.analyze_project import parse_args
-import unittest
-
PYTYPE_CFG = """
[pytype]
diff --git a/pytype/tools/analyze_project/parse_args.py b/pytype/tools/analyze_project/parse_args.py
index 7799940f..7856ba66 100644
--- a/pytype/tools/analyze_project/parse_args.py
+++ b/pytype/tools/analyze_project/parse_args.py
@@ -8,7 +8,6 @@ from pytype import datatypes
from pytype.tools import arg_parser
from pytype.tools.analyze_project import config
-
_ARG_PREFIX = '--'
diff --git a/pytype/tools/analyze_project/parse_args_test.py b/pytype/tools/analyze_project/parse_args_test.py
index 75c559f8..cbec1f66 100644
--- a/pytype/tools/analyze_project/parse_args_test.py
+++ b/pytype/tools/analyze_project/parse_args_test.py
@@ -3,11 +3,11 @@
import os
import sys
import types
+import unittest
from pytype import file_utils
from pytype.tools.analyze_project import config
from pytype.tools.analyze_project import parse_args
-import unittest
class TestParser(unittest.TestCase):
diff --git a/pytype/tools/analyze_project/pytype_runner.py b/pytype/tools/analyze_project/pytype_runner.py
index 9a774158..d5a55f94 100644
--- a/pytype/tools/analyze_project/pytype_runner.py
+++ b/pytype/tools/analyze_project/pytype_runner.py
@@ -9,7 +9,6 @@ from pytype import file_utils
from pytype import module_utils
from pytype.tools.analyze_project import config
-
# Generate a default pyi for builtin and system dependencies.
DEFAULT_PYI = """
from typing import Any
diff --git a/pytype/tools/analyze_project/pytype_runner_test.py b/pytype/tools/analyze_project/pytype_runner_test.py
index 35f81ede..3473abed 100644
--- a/pytype/tools/analyze_project/pytype_runner_test.py
+++ b/pytype/tools/analyze_project/pytype_runner_test.py
@@ -2,15 +2,15 @@
import collections
import os
+import unittest
+
+import six
from pytype import config as pytype_config
from pytype import file_utils
from pytype import module_utils
from pytype.tools.analyze_project import parse_args
from pytype.tools.analyze_project import pytype_runner
-import six
-import unittest
-
# Convenience aliases.
# pylint: disable=invalid-name
diff --git a/pytype/tools/annotate_ast/main.py b/pytype/tools/annotate_ast/main.py
index d6427da7..a18c2e43 100644
--- a/pytype/tools/annotate_ast/main.py
+++ b/pytype/tools/annotate_ast/main.py
@@ -3,11 +3,12 @@
import argparse
import sys
+from typed_ast import ast3
+from typed_ast import ast27 as ast27
+
from pytype.tools import arg_parser
from pytype.tools import debug
from pytype.tools.annotate_ast import annotate_ast
-from typed_ast import ast27 as ast27
-from typed_ast import ast3
def get_ast(options):
diff --git a/pytype/tools/arg_parser_test.py b/pytype/tools/arg_parser_test.py
index 023b7e13..3e1c1059 100644
--- a/pytype/tools/arg_parser_test.py
+++ b/pytype/tools/arg_parser_test.py
@@ -2,13 +2,12 @@
import argparse
import types
+import unittest
from pytype import config as pytype_config
from pytype import datatypes
from pytype.tools import arg_parser
-import unittest
-
class TestConvertString(unittest.TestCase):
"""Test arg_parser.convert_string."""
diff --git a/pytype/tools/config.py b/pytype/tools/config.py
index 96cf6b98..5448164c 100644
--- a/pytype/tools/config.py
+++ b/pytype/tools/config.py
@@ -1,6 +1,7 @@
"""Utilities for dealing with project configuration."""
import os
+
from six.moves import configparser
diff --git a/pytype/tools/config_test.py b/pytype/tools/config_test.py
index 0f19005d..620e9063 100644
--- a/pytype/tools/config_test.py
+++ b/pytype/tools/config_test.py
@@ -1,10 +1,10 @@
"""Tests for config.py."""
import textwrap
+import unittest
from pytype import file_utils
from pytype.tools import config
-import unittest
# TODO(rechen): How can we create and test a symlink loop?
diff --git a/pytype/tools/environment_test.py b/pytype/tools/environment_test.py
index 8817bc20..53181d9e 100644
--- a/pytype/tools/environment_test.py
+++ b/pytype/tools/environment_test.py
@@ -1,10 +1,10 @@
"""Tests for environment.py."""
import os
+import unittest
from pytype import file_utils
from pytype.tools import environment
-import unittest
class TestComputePythonPath(unittest.TestCase):
diff --git a/pytype/tools/merge_pyi/merge_pyi.py b/pytype/tools/merge_pyi/merge_pyi.py
index 583407fd..2dbe20a0 100644
--- a/pytype/tools/merge_pyi/merge_pyi.py
+++ b/pytype/tools/merge_pyi/merge_pyi.py
@@ -40,10 +40,6 @@ Finally, it knows that __init__() is supposed to return None.
import collections
import itertools
-import logging
-import os
-import sys
-
from lib2to3 import pygram
from lib2to3 import pytree
from lib2to3 import refactor
@@ -56,6 +52,9 @@ from lib2to3.patcomp import compile_pattern
from lib2to3.pgen2 import driver
from lib2to3.pytree import Leaf
from lib2to3.pytree import Node
+import logging
+import os
+import sys
__all__ = ['KnownError',
'FixMergePyi',
diff --git a/pytype/tools/merge_pyi/merge_pyi_test.py b/pytype/tools/merge_pyi/merge_pyi_test.py
index b1f4195b..bc7c939a 100644
--- a/pytype/tools/merge_pyi/merge_pyi_test.py
+++ b/pytype/tools/merge_pyi/merge_pyi_test.py
@@ -4,10 +4,9 @@ import logging
import os
import re
import sys
-
-from pytype.tools.merge_pyi import merge_pyi
import unittest
+from pytype.tools.merge_pyi import merge_pyi
__all__ = ('TestBuilder', 'load_tests')
diff --git a/pytype/tools/merge_pyi/test_data/any.comment.py b/pytype/tools/merge_pyi/test_data/any.comment.py
index 12a026ca..db25257d 100644
--- a/pytype/tools/merge_pyi/test_data/any.comment.py
+++ b/pytype/tools/merge_pyi/test_data/any.comment.py
@@ -2,6 +2,7 @@
import typing
from typing import Any, Text
+
def f(x, y):
# type: (Any, Text) -> typing.List
return []
diff --git a/pytype/tools/merge_pyi/test_data/heuristics.comment.py b/pytype/tools/merge_pyi/test_data/heuristics.comment.py
index 21ca8390..9b2f7722 100644
--- a/pytype/tools/merge_pyi/test_data/heuristics.comment.py
+++ b/pytype/tools/merge_pyi/test_data/heuristics.comment.py
@@ -1,4 +1,5 @@
from typing import Any
+
# If not annotate_pep484, info in pyi files is augmented with heuristics to decide if un-annotated
# arguments are "Any" or "" (like "self")
diff --git a/pytype/tools/merge_pyi/test_data/imports.comment.py b/pytype/tools/merge_pyi/test_data/imports.comment.py
index 4865439a..4d807e16 100644
--- a/pytype/tools/merge_pyi/test_data/imports.comment.py
+++ b/pytype/tools/merge_pyi/test_data/imports.comment.py
@@ -6,11 +6,13 @@ import m3
from m4 import D
from m5.sub import E
from m6 import F
-from mStar import *
from m7 import a
from m8 import b
+from mStar import *
+
from ......m9 import c
+
def f(a1, a2, a3, a4, a5, a6):
# type: (A, B, m3.C, D, E, F) -> G
pass
diff --git a/pytype/tools/merge_pyi/test_data/imports.pep484.py b/pytype/tools/merge_pyi/test_data/imports.pep484.py
index f1f10c72..f7724d8c 100644
--- a/pytype/tools/merge_pyi/test_data/imports.pep484.py
+++ b/pytype/tools/merge_pyi/test_data/imports.pep484.py
@@ -6,11 +6,13 @@ import m3
from m4 import D
from m5.sub import E
from m6 import F
-from mStar import *
from m7 import a
from m8 import b
+from mStar import *
+
from ......m9 import c
+
def f(a1: A, a2: B, a3: m3.C, a4: D, a5: E, a6: F) -> G:
pass
diff --git a/pytype/tools/merge_pyi/test_data/imports.py b/pytype/tools/merge_pyi/test_data/imports.py
index bee7b2bc..3b03ec01 100644
--- a/pytype/tools/merge_pyi/test_data/imports.py
+++ b/pytype/tools/merge_pyi/test_data/imports.py
@@ -1,6 +1,7 @@
import existing_import
from existing_import import d
+
def f(a1, a2, a3, a4, a5, a6):
pass
diff --git a/pytype/tools/merge_pyi/test_data/imports.pyi b/pytype/tools/merge_pyi/test_data/imports.pyi
index 3d0106ad..01aa0dba 100644
--- a/pytype/tools/merge_pyi/test_data/imports.pyi
+++ b/pytype/tools/merge_pyi/test_data/imports.pyi
@@ -1,18 +1,23 @@
# Following imports need to be copied into .py
+import existing_import
+from existing_import import d
from m1 import A
-from m2 import B, B2
+from m2 import B
+from m2 import B2
import m3
-from m4 import (D,
-D2)
+from m4 import D
+from m4 import D2
from m5.sub import E
from m6 import F
+from m7 import a
+from m7 import a2
+from m7 import a3
+from m8 import b
+from m8 import b2
from mStar import * # G
-from m7 import (a, a2, a3)
-from m8 import (b, b2, )
+
from ......m9 import c
-import existing_import
-from existing_import import d
def f(a1: A, a2: B, a3: m3.C, a4: D, a5: E, a6: F) -> G: ...
def g(a7: a, a8: b, a9: c, a10: d) -> existing_import: ...
diff --git a/pytype/tools/merge_pyi/test_data/imports_alias.comment.py b/pytype/tools/merge_pyi/test_data/imports_alias.comment.py
index 2bccad5e..b42f8c2c 100644
--- a/pytype/tools/merge_pyi/test_data/imports_alias.comment.py
+++ b/pytype/tools/merge_pyi/test_data/imports_alias.comment.py
@@ -4,6 +4,7 @@ from m2 import B_old as B
from m3 import C_old as C
import m4_old as m4
+
def f(a, b, c):
# type: (A, B, C) -> m4.D
pass
diff --git a/pytype/tools/merge_pyi/test_data/imports_alias.pep484.py b/pytype/tools/merge_pyi/test_data/imports_alias.pep484.py
index 364e5ae9..395a7582 100644
--- a/pytype/tools/merge_pyi/test_data/imports_alias.pep484.py
+++ b/pytype/tools/merge_pyi/test_data/imports_alias.pep484.py
@@ -4,5 +4,6 @@ from m2 import B_old as B
from m3 import C_old as C
import m4_old as m4
+
def f(a: A, b: B, c: C) -> m4.D:
pass
diff --git a/pytype/tools/merge_pyi/test_data/imports_alias.pyi b/pytype/tools/merge_pyi/test_data/imports_alias.pyi
index eb73565e..42a62a6f 100644
--- a/pytype/tools/merge_pyi/test_data/imports_alias.pyi
+++ b/pytype/tools/merge_pyi/test_data/imports_alias.pyi
@@ -1,6 +1,8 @@
from m1 import A_old as A
-from m2 import something, B_old as B
-from m3 import C_old as C, otherthing as Other
+from m2 import B_old as B
+from m2 import something
+from m3 import C_old as C
+from m3 import otherthing as Other
import m4_old as m4
def f(a: A, b: B, c: C) -> m4.D: ...
diff --git a/pytype/tools/merge_pyi/test_data/imports_multiple.comment.py b/pytype/tools/merge_pyi/test_data/imports_multiple.comment.py
index 3dbbccfb..f561fa1d 100644
--- a/pytype/tools/merge_pyi/test_data/imports_multiple.comment.py
+++ b/pytype/tools/merge_pyi/test_data/imports_multiple.comment.py
@@ -1,6 +1,7 @@
"""Test multiple from-imports."""
from typing import List, Text
+
def f():
# type: () -> List[Text]
return []
diff --git a/pytype/tools/merge_pyi/test_data/imports_multiple.pep484.py b/pytype/tools/merge_pyi/test_data/imports_multiple.pep484.py
index b020cc27..63f79125 100644
--- a/pytype/tools/merge_pyi/test_data/imports_multiple.pep484.py
+++ b/pytype/tools/merge_pyi/test_data/imports_multiple.pep484.py
@@ -1,5 +1,6 @@
"""Test multiple from-imports."""
from typing import List, Text
+
def f() -> List[Text]:
return []
diff --git a/pytype/tools/merge_pyi/test_data/partial.comment.py b/pytype/tools/merge_pyi/test_data/partial.comment.py
index e9b5370e..9ac35722 100644
--- a/pytype/tools/merge_pyi/test_data/partial.comment.py
+++ b/pytype/tools/merge_pyi/test_data/partial.comment.py
@@ -1,4 +1,6 @@
from typing import Any
+
+
def f1(a, b : int):
pass
diff --git a/pytype/tools/merge_pyi/test_data/pyi_variations.comment.py b/pytype/tools/merge_pyi/test_data/pyi_variations.comment.py
index fd8950e6..461a208a 100644
--- a/pytype/tools/merge_pyi/test_data/pyi_variations.comment.py
+++ b/pytype/tools/merge_pyi/test_data/pyi_variations.comment.py
@@ -1,4 +1,6 @@
from typing import Any
+
+
def f1(x):
# type: (e1) -> r1
pass
diff --git a/pytype/tools/merge_pyi/test_data/redefine.comment.py b/pytype/tools/merge_pyi/test_data/redefine.comment.py
index f220961c..cfc7077c 100644
--- a/pytype/tools/merge_pyi/test_data/redefine.comment.py
+++ b/pytype/tools/merge_pyi/test_data/redefine.comment.py
@@ -1,4 +1,6 @@
from typing import Any
+
+
def f1(x):
# type: (Any) -> Union[int, str]
return 1
diff --git a/pytype/tools/merge_pyi/test_data/retval_heuristics.comment.py b/pytype/tools/merge_pyi/test_data/retval_heuristics.comment.py
index 8bd2c114..0e4658f2 100644
--- a/pytype/tools/merge_pyi/test_data/retval_heuristics.comment.py
+++ b/pytype/tools/merge_pyi/test_data/retval_heuristics.comment.py
@@ -1,4 +1,5 @@
from typing import Any
+
# With heuristics, have to pick between returning None or Any. If generating comment annotations,
# heuristics matter even if we have a pyi
diff --git a/pytype/tools/merge_pyi/test_data/simple.comment.py b/pytype/tools/merge_pyi/test_data/simple.comment.py
index 1b8f2e16..cda925d9 100644
--- a/pytype/tools/merge_pyi/test_data/simple.comment.py
+++ b/pytype/tools/merge_pyi/test_data/simple.comment.py
@@ -1,4 +1,6 @@
from typing import Any
+
+
def f1(a, b):
# type: (Any, Any) -> r1
"""Doc"""
diff --git a/pytype/tools/tool_utils_test.py b/pytype/tools/tool_utils_test.py
index ad174e53..cbfbeb4b 100644
--- a/pytype/tools/tool_utils_test.py
+++ b/pytype/tools/tool_utils_test.py
@@ -1,10 +1,10 @@
"""Tests for tool_utils.py."""
import os
+import unittest
from pytype import file_utils
from pytype.tools import tool_utils
-import unittest
class TestSetupLoggingOrDie(unittest.TestCase):
diff --git a/pytype/tools/traces/run.py b/pytype/tools/traces/run.py
index 1f105d87..9efaaad7 100644
--- a/pytype/tools/traces/run.py
+++ b/pytype/tools/traces/run.py
@@ -2,6 +2,7 @@
import argparse
import sys
+
from pytype import config
from pytype.tools.traces import traces
diff --git a/pytype/tools/traces/source.py b/pytype/tools/traces/source.py
index ca14e904..3164618a 100644
--- a/pytype/tools/traces/source.py
+++ b/pytype/tools/traces/source.py
@@ -4,7 +4,6 @@ import collections
from pytype import compat
-
Location = collections.namedtuple("Location", ("line", "column"))
diff --git a/pytype/tools/traces/source_test.py b/pytype/tools/traces/source_test.py
index 9829d566..2c41a745 100644
--- a/pytype/tools/traces/source_test.py
+++ b/pytype/tools/traces/source_test.py
@@ -2,10 +2,12 @@
# Lint as: python2, python3
"""Tests for traces.source."""
-from pytype.tools.traces import source
-import six
import unittest
+import six
+
+from pytype.tools.traces import source
+
class _FakeOpcode:
diff --git a/pytype/tools/traces/traces.py b/pytype/tools/traces/traces.py
index 0e10e0b0..625da6de 100644
--- a/pytype/tools/traces/traces.py
+++ b/pytype/tools/traces/traces.py
@@ -11,7 +11,6 @@ from pytype import load_pytd
from pytype.pytd import pytd
from pytype.pytd import pytd_utils
from pytype.pytd import visitors
-
from pytype.tools.traces import source
from pytype.tools.traces import visitor
diff --git a/pytype/tools/traces/traces_test.py b/pytype/tools/traces/traces_test.py
index b25fbe8b..1a157d85 100644
--- a/pytype/tools/traces/traces_test.py
+++ b/pytype/tools/traces/traces_test.py
@@ -4,13 +4,14 @@ import ast
import collections
import sys
import textwrap
+import unittest
+
from pytype import config
from pytype import file_utils
from pytype.pytd import pytd
from pytype.pytd import pytd_utils
from pytype.tests import test_utils
from pytype.tools.traces import traces
-import unittest
class _NotImplementedVisitor(traces.MatchAstVisitor):
diff --git a/pytype/tools/traces/visitor_test.py b/pytype/tools/traces/visitor_test.py
index cc56469d..d6ca30b4 100644
--- a/pytype/tools/traces/visitor_test.py
+++ b/pytype/tools/traces/visitor_test.py
@@ -3,9 +3,10 @@
import ast
import sys
import textwrap
-from pytype.tools.traces import visitor
import unittest
+from pytype.tools.traces import visitor
+
class _VisitOrderVisitor(visitor.BaseVisitor):
"""Tests visit order."""
diff --git a/pytype/tools/xref/callgraph.py b/pytype/tools/xref/callgraph.py
index 230494f0..a93699db 100644
--- a/pytype/tools/xref/callgraph.py
+++ b/pytype/tools/xref/callgraph.py
@@ -3,6 +3,7 @@
import collections
import attr
+
from pytype.pytd import pytd
from pytype.pytd import pytd_utils
diff --git a/pytype/tools/xref/callgraph_test.py b/pytype/tools/xref/callgraph_test.py
index bbef9534..9cba8c4d 100644
--- a/pytype/tools/xref/callgraph_test.py
+++ b/pytype/tools/xref/callgraph_test.py
@@ -1,6 +1,5 @@
from pytype import config
from pytype import file_utils
-
from pytype.tests import test_base
from pytype.tests import test_utils
from pytype.tools.xref import indexer
diff --git a/pytype/tools/xref/indexer.py b/pytype/tools/xref/indexer.py
index a34b56b8..82fe41ae 100644
--- a/pytype/tools/xref/indexer.py
+++ b/pytype/tools/xref/indexer.py
@@ -5,6 +5,9 @@ import re
from typing import Optional
import attr
+from typed_ast import ast3
+from typed_ast import ast27 as ast27
+
from pytype import abstract
from pytype import analyze
from pytype import config
@@ -18,14 +21,9 @@ from pytype.pytd import visitors
from pytype.tools.traces import source
from pytype.tools.traces import traces
from pytype.tools.traces import visitor as ast_visitor
-
from pytype.tools.xref import callgraph
-from pytype.tools.xref import utils as xref_utils
from pytype.tools.xref import node_utils
-
-from typed_ast import ast27 as ast27
-from typed_ast import ast3
-
+from pytype.tools.xref import utils as xref_utils
# A mapping of offsets between a node's start position and the symbol being
# defined. e.g. in the declaration "class X" the X is at +6 from the start.
diff --git a/pytype/tools/xref/indexer_test.py b/pytype/tools/xref/indexer_test.py
index 6286644d..fdad2518 100644
--- a/pytype/tools/xref/indexer_test.py
+++ b/pytype/tools/xref/indexer_test.py
@@ -5,10 +5,8 @@ from pytype import abstract
from pytype import config
from pytype import file_utils
from pytype import utils
-
from pytype.tests import test_base
from pytype.tests import test_utils
-
from pytype.tools.xref import indexer
from pytype.tools.xref import kythe
from pytype.tools.xref import output
diff --git a/pytype/tools/xref/kythe.py b/pytype/tools/xref/kythe.py
index 5e698841..31a806fe 100644
--- a/pytype/tools/xref/kythe.py
+++ b/pytype/tools/xref/kythe.py
@@ -3,9 +3,8 @@
import base64
import collections
-from pytype.tools.xref import utils as xref_utils
from pytype.tools.xref import indexer
-
+from pytype.tools.xref import utils as xref_utils
FILE_ANCHOR_SIGNATURE = ":module:"
diff --git a/pytype/tools/xref/main.py b/pytype/tools/xref/main.py
index 2e099e1f..7dd6828b 100644
--- a/pytype/tools/xref/main.py
+++ b/pytype/tools/xref/main.py
@@ -6,7 +6,6 @@ import traceback
from pytype import utils
from pytype.pytd.parse import node
-
from pytype.tools.xref import debug
from pytype.tools.xref import indexer
from pytype.tools.xref import kythe
diff --git a/pytype/tools/xref/parse_args_test.py b/pytype/tools/xref/parse_args_test.py
index 63ef3ef5..24bf25a4 100644
--- a/pytype/tools/xref/parse_args_test.py
+++ b/pytype/tools/xref/parse_args_test.py
@@ -1,8 +1,9 @@
"""Tests for parse_args.py."""
+import unittest
+
from pytype import file_utils
from pytype.tools.xref import parse_args
-import unittest
class TestParseArgs(unittest.TestCase):
diff --git a/pytype/tools/xref/testdata/imports.py b/pytype/tools/xref/testdata/imports.py
index 51992d00..e2a8842e 100644
--- a/pytype/tools/xref/testdata/imports.py
+++ b/pytype/tools/xref/testdata/imports.py
@@ -1,32 +1,32 @@
# pylint: skip-file
#- @#0os ref/imports ModuleOs
-import os
#- @#0os ref/imports ModuleOs
#- @os_alias defines/binding OsAlias
#- OsAlias.node/kind variable
#- OsAlias.subkind import
#- OsAlias aliases ModuleOs
+import os
import os as os_alias
-
#- @"os.path" ref/imports ModuleOsPath
import os.path
+
#- @os ref ModuleOs
#- @path ref ModuleOsPath
os.path.exists
#- @path ref/imports ModuleOsPath
from os import path
+
#- @path ref ModuleOsPath
path.exists
#- @name ref OsName
os.name
-#- @name ref/imports OsName
-from os import name
-
#- @name_alias defines/binding OsNameAlias
#- OsNameAlias.node/kind variable
#- OsNameAlias.subkind import
#- OsNameAlias aliases OsName
+#- @name ref/imports OsName
+from os import name
from os import name as name_alias
diff --git a/pytype/typegraph/cfg_test.py b/pytype/typegraph/cfg_test.py
index 272311c9..cc8bfc70 100644
--- a/pytype/typegraph/cfg_test.py
+++ b/pytype/typegraph/cfg_test.py
@@ -1,10 +1,10 @@
"""Test for the cfg Python extension module."""
-from pytype.typegraph import cfg
+import unittest
import six
-import unittest
+from pytype.typegraph import cfg
class CFGTest(unittest.TestCase):
diff --git a/pytype/typegraph/cfg_utils.py b/pytype/typegraph/cfg_utils.py
index 2d41bd65..f42f1467 100644
--- a/pytype/typegraph/cfg_utils.py
+++ b/pytype/typegraph/cfg_utils.py
@@ -3,7 +3,6 @@
import collections
import itertools
-
# Limit on how many argument combinations we allow before aborting.
# For a sample of 16664 (sane) source files without imports, these are the
# quantiles that were below the given number of argument combinations:
diff --git a/pytype/typegraph/cfg_utils_test.py b/pytype/typegraph/cfg_utils_test.py
index 13318e7b..2d7e873f 100644
--- a/pytype/typegraph/cfg_utils_test.py
+++ b/pytype/typegraph/cfg_utils_test.py
@@ -1,12 +1,12 @@
"""Tests for the additional CFG utilities."""
import itertools
+import unittest
-from pytype.typegraph import cfg
-from pytype.typegraph import cfg_utils
import six
-import unittest
+from pytype.typegraph import cfg
+from pytype.typegraph import cfg_utils
class CFGUtilTest(unittest.TestCase):
diff --git a/pytype/utils.py b/pytype/utils.py
index 16b8bc6c..7d6107fb 100644
--- a/pytype/utils.py
+++ b/pytype/utils.py
@@ -13,7 +13,6 @@ import weakref
from pytype import pytype_source_utils
-
# Set this value to True to indicate that pytype is running under a 2.7
# interpreter with the type annotations patch applied.
USE_ANNOTATIONS_BACKPORT = False
diff --git a/pytype/utils_test.py b/pytype/utils_test.py
index 59867f14..27004ef9 100644
--- a/pytype/utils_test.py
+++ b/pytype/utils_test.py
@@ -1,9 +1,10 @@
"""Tests for utils.py."""
-from pytype import utils
+import unittest
+
import six
-import unittest
+from pytype import utils
class UtilsTest(unittest.TestCase):
diff --git a/pytype/vm.py b/pytype/vm.py
index ff9c6a02..c91bbd96 100644
--- a/pytype/vm.py
+++ b/pytype/vm.py
@@ -17,6 +17,8 @@ import logging
import os
import re
+import six
+
from pytype import abstract
from pytype import abstract_utils
from pytype import annotations_util
@@ -27,12 +29,12 @@ from pytype import convert
from pytype import datatypes
from pytype import directors
from pytype import function
-from pytype import overlay_dict
from pytype import load_pytd
from pytype import matcher
from pytype import metaclass
from pytype import metrics
from pytype import mixin
+from pytype import overlay_dict
from pytype import special_builtins
from pytype import state as frame_state
from pytype import utils
@@ -45,7 +47,6 @@ from pytype.pytd import slots
from pytype.pytd import visitors
from pytype.typegraph import cfg
from pytype.typegraph import cfg_utils
-import six
log = logging.getLogger(__name__)
diff --git a/pytype/vm_test.py b/pytype/vm_test.py
index f5aed5b4..45dda214 100644
--- a/pytype/vm_test.py
+++ b/pytype/vm_test.py
@@ -2,6 +2,8 @@
import textwrap
+import six
+
from pytype import analyze
from pytype import blocks
from pytype import compat
@@ -13,8 +15,6 @@ from pytype.pyc import pyc
from pytype.tests import test_base
from pytype.tests import test_utils
-import six
-
_PY2_OPMAP = {v.__name__: k for k, v in opcodes.python2_mapping.items()}
diff --git a/setup.py b/setup.py
index 764a1622..34fdd3eb 100644
--- a/setup.py
+++ b/setup.py
@@ -10,7 +10,8 @@ import re
import shutil
import sys
-from setuptools import setup, Extension # pylint: disable=g-multiple-import
+from setuptools import Extension # pylint: disable=g-multiple-import
+from setuptools import setup
# Path to directory containing setup.py
here = os.path.abspath(os.path.dirname(__file__))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment