summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2017-05-05 14:47:25 -0700
committerJon Dufresne <jon.dufresne@gmail.com>2017-05-05 14:52:29 -0700
commitbbe111f0896492b0211157649ac63eb3cd0645a1 (patch)
treea5202e6a08c76cafaead387ce94c27319706e04b
parentd060e7a5441484e182c106bcd83e74c411bd6020 (diff)
downloadisort-bbe111f0896492b0211157649ac63eb3cd0645a1.tar.gz
Clean up some flake8 warnings and errors
-rw-r--r--isort/isort.py14
-rwxr-xr-xisort/main.py10
-rw-r--r--isort/pie_slice.py3
-rw-r--r--isort/settings.py2
-rw-r--r--runtests.py1
-rw-r--r--test_isort.py10
6 files changed, 21 insertions, 19 deletions
diff --git a/isort/isort.py b/isort/isort.py
index 17be1afa..dceafab5 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -40,7 +40,7 @@ from glob import glob
from . import settings
from .natural import nsorted
-from .pie_slice import *
+from .pie_slice import itemsview
KNOWN_SECTION_MAPPING = {
'STDLIB': 'STANDARD_LIBRARY',
@@ -55,7 +55,7 @@ class SortImports(object):
skipped = False
def __init__(self, file_path=None, file_contents=None, write_to_stdout=False, check=False,
- show_diff=False, settings_path=None, ask_to_apply=False, **setting_overrides):
+ show_diff=False, settings_path=None, ask_to_apply=False, **setting_overrides):
if not settings_path and file_path:
settings_path = os.path.dirname(os.path.abspath(file_path))
settings_path = settings_path or os.getcwd()
@@ -265,7 +265,7 @@ class SortImports(object):
is_package = exists_case_sensitive(package_path) and os.path.isdir(package_path)
if is_module or is_package:
if ('site-packages' in prefix or 'dist-packages' in prefix or
- (virtual_env and virtual_env_src in prefix)):
+ (virtual_env and virtual_env_src in prefix)):
return self.sections.THIRDPARTY
elif os.path.normcase(prefix).startswith(stdlib_lib_prefix):
return self.sections.STDLIB
@@ -447,8 +447,8 @@ class SortImports(object):
do_multiline_reformat = True
# If line too long AND have imports AND we are NOT using GRID or VERTICAL wrap modes
- if (len(import_statement) > self.config['line_length'] and len(from_imports) > 0
- and self.config.get('multi_line_output', 0) not in (1, 0)):
+ if (len(import_statement) > self.config['line_length'] and len(from_imports) > 0 and
+ self.config.get('multi_line_output', 0) not in (1, 0)):
do_multiline_reformat = True
if do_multiline_reformat:
@@ -871,8 +871,8 @@ class SortImports(object):
if len(self.out_lines) > max(self.import_index, self._first_comment_index_end, 1) - 1:
last = self.out_lines and self.out_lines[-1].rstrip() or ""
- while (last.startswith("#") and not last.endswith('"""') and not last.endswith("'''")
- and not 'isort:imports-' in last):
+ while (last.startswith("#") and not last.endswith('"""') and not last.endswith("'''") and
+ not 'isort:imports-' in last):
self.comments['above']['straight'].setdefault(module, []).insert(0,
self.out_lines.pop(-1))
if len(self.out_lines) > 0:
diff --git a/isort/main.py b/isort/main.py
index 011e38d4..4df83863 100755
--- a/isort/main.py
+++ b/isort/main.py
@@ -30,7 +30,7 @@ import setuptools
from isort import SortImports, __version__
from isort.settings import DEFAULT_SECTIONS, default, from_path, should_skip
-from .pie_slice import *
+from .pie_slice import itemsview
INTRO = r"""
@@ -218,7 +218,7 @@ def create_parser():
help='Shows verbose output, such as when files are skipped or when a check is successful.')
parser.add_argument('-q', '--quiet', action='store_true', dest="quiet",
help='Shows extra quiet output, only errors are outputted.')
- parser.add_argument('-sp', '--settings-path', dest="settings_path",
+ parser.add_argument('-sp', '--settings-path', dest="settings_path",
help='Explicitly set the settings path instead of auto determining based on file location.')
parser.add_argument('-ff', '--from-first', dest='from_first',
help="Switches the typical ordering preference, showing from imports first then straight ones.")
@@ -227,12 +227,12 @@ def create_parser():
parser.add_argument('-fgw', '--force-grid-wrap', nargs='?', const=2, type=int, dest="force_grid_wrap",
help='Force number of from imports (defaults to 2) to be grid wrapped regardless of line '
'length')
- parser.add_argument('-fass', '--force-alphabetical-sort-within-sections', action='store_true',
+ parser.add_argument('-fass', '--force-alphabetical-sort-within-sections', action='store_true',
dest="force_alphabetical_sort", help='Force all imports to be sorted alphabetically within a '
'section')
- parser.add_argument('-fas', '--force-alphabetical-sort', action='store_true', dest="force_alphabetical_sort",
+ parser.add_argument('-fas', '--force-alphabetical-sort', action='store_true', dest="force_alphabetical_sort",
help='Force all imports to be sorted as a single section')
- parser.add_argument('-fss', '--force-sort-within-sections', action='store_true', dest="force_sort_within_sections",
+ parser.add_argument('-fss', '--force-sort-within-sections', action='store_true', dest="force_sort_within_sections",
help='Force imports to be sorted by module, independent of import_type')
parser.add_argument('-lbt', '--lines-between-types', dest='lines_between_types', type=int)
diff --git a/isort/pie_slice.py b/isort/pie_slice.py
index d8a35769..c546ae77 100644
--- a/isort/pie_slice.py
+++ b/isort/pie_slice.py
@@ -67,6 +67,7 @@ def with_metaclass(meta, *bases):
class metaclass(meta):
__call__ = type.__call__
__init__ = type.__init__
+
def __new__(cls, name, this_bases, d):
if this_bases is None:
return type.__new__(cls, name, (), d)
@@ -428,7 +429,7 @@ if sys.version_info[0] == 2 and sys.version_info[1] < 7:
if isinstance(other, OrderedDict):
if len(self) != len(other):
return False
- for p, q in zip(self.items(), other.items()):
+ for p, q in zip(self.items(), other.items()):
if p != q:
return False
return True
diff --git a/isort/settings.py b/isort/settings.py
index af7d53a3..937f518a 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -28,7 +28,7 @@ import fnmatch
import os
from collections import namedtuple
-from .pie_slice import *
+from .pie_slice import itemsview, lru_cache, native_str
try:
import configparser
diff --git a/runtests.py b/runtests.py
index a024d3d5..4109bde0 100644
--- a/runtests.py
+++ b/runtests.py
@@ -2678,6 +2678,7 @@ class DictImporter(object):
res = self.sources.get(name + '.__init__')
return res
+
if __name__ == "__main__":
if sys.version_info >= (3, 0):
exec("def do_exec(co, loc): exec(co, loc)\n")
diff --git a/test_isort.py b/test_isort.py
index 0559f3d0..866ce8f6 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -29,7 +29,7 @@ import shutil
import sys
import tempfile
-from isort.isort import exists_case_sensitive, SortImports
+from isort.isort import SortImports, exists_case_sensitive
from isort.pie_slice import *
from isort.settings import WrapModes
@@ -1700,7 +1700,7 @@ def test_sections_parsed_correct():
def test_alphabetic_sorting_no_newlines():
'''Test to ensure that alphabetical sort does not erroneously introduce new lines (issue #328)'''
test_input = "import os\n"
- test_output = SortImports(file_contents=test_input,force_alphabetical_sort_within_sections=True).output
+ test_output = SortImports(file_contents=test_input, force_alphabetical_sort_within_sections=True).output
assert test_input == test_output
test_input = ('import os\n'
@@ -1710,7 +1710,7 @@ def test_alphabetic_sorting_no_newlines():
'\n'
'\n'
'print(1)\n')
- test_output = SortImports(file_contents=test_input,force_alphabetical_sort_within_sections=True, lines_after_imports=2).output
+ test_output = SortImports(file_contents=test_input, force_alphabetical_sort_within_sections=True, lines_after_imports=2).output
assert test_input == test_output
@@ -1720,7 +1720,7 @@ def test_sort_within_section():
'import foo\n'
'from foo import bar\n'
'from foo.bar import Quux, baz\n')
- test_output = SortImports(file_contents=test_input,force_sort_within_sections=True).output
+ test_output = SortImports(file_contents=test_input, force_sort_within_sections=True).output
assert test_output == test_input
test_input = ('import foo\n'
@@ -1728,7 +1728,7 @@ def test_sort_within_section():
'from foo.bar import baz\n'
'from foo.bar import Quux\n'
'from Foob import ar\n')
- test_output = SortImports(file_contents=test_input,force_sort_within_sections=True, order_by_type=False,
+ test_output = SortImports(file_contents=test_input, force_sort_within_sections=True, order_by_type=False,
force_single_line=True).output
assert test_output == test_input