Repository: timothycrosley/isort
Pull request #547 (2017-06-01 18:15:49)

Feature/hotfix release 2


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c55055d9..59e3cd68 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,7 +1,11 @@
 Changelog
 =========
-### 4.2.9 - June 1, 2017 - hotfix release
+### 4.2.10 - June 1, 2017 - hotfix release
 IMPORTANT NOTE: This will be the last release with Python 2.6 support, subsequent releases will be 2.7+ only
+- Fixed #546: Can't select y/n/c after latest update
+- Fixed #545: Incorrectly moves __future__ imports above encoding comments
+
+### 4.2.9 - June 1, 2017 - hotfix release
 - Fixed #428: Check only modifies sorting
 - Fixed #540: Not correctly identifying stdlib modules
 
diff --git a/isort/__init__.py b/isort/__init__.py
index d906c27d..01c01231 100644
--- a/isort/__init__.py
+++ b/isort/__init__.py
@@ -25,4 +25,4 @@ from __future__ import absolute_import, division, print_function, unicode_litera
 from . import settings
 from .isort import SortImports
 
-__version__ = "4.2.9"
+__version__ = "4.2.10"
diff --git a/isort/isort.py b/isort/isort.py
index d4664ce2..d9b4f31b 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 OrderedDict, OrderedSet, itemsview
+from .pie_slice import OrderedDict, OrderedSet, input, itemsview
 
 KNOWN_SECTION_MAPPING = {
     'STDLIB': 'STANDARD_LIBRARY',
@@ -902,7 +902,8 @@ class SortImports(object):
                             self.comments['straight'][module] = comments
                             comments = None
 
-                        if len(self.out_lines) > max(self.import_index, self._first_comment_index_end, 1) - 1:
+                        if len(self.out_lines) > max(self.import_index, self._first_comment_index_end + 1, 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):
diff --git a/isort/pie_slice.py b/isort/pie_slice.py
index 5079990f..bfb341a7 100644
--- a/isort/pie_slice.py
+++ b/isort/pie_slice.py
@@ -120,6 +120,7 @@ if PY3:
     import builtins
     from urllib import parse
 
+    input = input
     integer_types = (int, )
 
     def u(string):
diff --git a/setup.py b/setup.py
index 8c89da64..38efbac5 100755
--- a/setup.py
+++ b/setup.py
@@ -39,7 +39,7 @@ with open('README.rst', 'r') as f:
     readme = f.read()
 
 setup(name='isort',
-      version='4.2.9',
+      version='4.2.10',
       description='A Python utility / library to sort Python imports.',
       long_description=readme,
       author='Timothy Crosley',


Test patch:
diff --git a/test_isort.py b/test_isort.py
index b4d458ce..67eccc03 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -2116,3 +2116,19 @@ def test_correct_number_of_new_lines_with_comment_issue_435():
                   'def baz():\n'
                   '    pass\n')
     assert SortImports(file_contents=test_input).output == test_input
+
+
+def test_future_below_encoding_issue_545():
+    """Test to ensure future is always below comment"""
+    test_input = ('#!/usr/bin/env python\n'
+                  'from __future__ import print_function\n'
+                  'import logging\n'
+                  '\n'
+                  'print("hello")\n')
+    expected_output = ('#!/usr/bin/env python\n'
+                       'from __future__ import print_function\n'
+                       '\n'
+                       'import logging\n'
+                       '\n'
+                       'print("hello")\n')
+    assert SortImports(file_contents=test_input).output == expected_output