summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2019-03-08 00:30:01 -0800
committerTimothy Crosley <timothy.crosley@gmail.com>2019-03-08 00:55:59 -0800
commite1f83dd486b0a5e28fcb51f1bd2b8c42fd6b692c (patch)
tree92ef7e829195a1acd7b0dd8fb85f2f752caa5dfd
parent08a0265a2258a2b8d7e3b9f959629d7d92134f5f (diff)
downloadisort-e1f83dd486b0a5e28fcb51f1bd2b8c42fd6b692c.tar.gz
Fix issue #889: Isort should not add blank lines to beginning of file
-rw-r--r--CHANGELOG.md3
-rw-r--r--isort/isort.py2
-rw-r--r--test_isort.py8
3 files changed, 11 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a73e70c4..4b8c5406 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,7 +15,8 @@ Planned:
### 4.3.13 - March 6, 2019 - hot fix release
- Fixed the inability to accurately determine import section when a mix of conda and virtual environments are used.
- Fixed some output being printed even when --quiet mode is enabled.
-- Fixed issue #890 interoperability with PyCharm by allowing case sensitive non type grouped sorting
+- Fixed issue #890 interoperability with PyCharm by allowing case sensitive non type grouped sorting.
+- Fixed issue #889 under some circumstances isort will incorrectly add a new line at the beginning of a file.
### 4.3.12 - March 6, 2019 - hot fix release
- Fix error caused when virtual environment not detected
diff --git a/isort/isort.py b/isort/isort.py
index 8024e347..8968d5df 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -1072,7 +1072,7 @@ class SortImports(object):
'isort:imports-' not in last):
self.comments['above']['straight'].setdefault(module, []).insert(0,
self.out_lines.pop(-1))
- if len(self.out_lines) > 0:
+ if len(self.out_lines) > 0 and len(self.out_lines) != self._first_comment_index_end:
last = self.out_lines[-1].rstrip()
else:
last = ""
diff --git a/test_isort.py b/test_isort.py
index fce3e3f0..d65d4b9f 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -2901,3 +2901,11 @@ def test_ensure_support_for_non_typed_but_cased_alphabetic_sort_issue_890():
'from pkg import recorder\n')
assert SortImports(file_contents=test_input, case_sensitive=True, order_by_type=False,
force_single_line=True).output == expected_output
+
+
+def test_to_ensure_empty_line_not_added_to_file_start_issue_889():
+ test_input = ('# comment\n'
+ 'import os\n'
+ '# comment2\n'
+ 'import sys\n')
+ assert SortImports(file_contents=test_input).output == test_input