summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Edmund Crosley <timothy.crosley@gmail.com>2019-02-23 14:36:51 -0800
committerGitHub <noreply@github.com>2019-02-23 14:36:51 -0800
commitb2bcda6031ef191c5672d3af52e6bb52c551f464 (patch)
tree843346863c4d7a967c0e76f65ef586d9057083db
parentb03c5b7506ec9307b4d2c37dec2f2a075c8f9fc8 (diff)
parent1ed9402c005163f5ed787c9bf48a33affa295956 (diff)
downloadisort-b2bcda6031ef191c5672d3af52e6bb52c551f464.tar.gz
Merge pull request #819 from timothycrosley/feature/fix-issue-576
Fix issue 576
-rw-r--r--isort/isort.py4
-rw-r--r--test_isort.py7
2 files changed, 11 insertions, 0 deletions
diff --git a/isort/isort.py b/isort/isort.py
index 970117f1..df075bc2 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -400,6 +400,10 @@ class SortImports(object):
while from_imports and from_imports[0] in as_imports:
from_import = from_imports.pop(0)
from_comments = self.comments['straight'].get('{}.{}'.format(module, from_import))
+ above_comments = self.comments['above']['from'].pop(module, None)
+ if above_comments:
+ section_output.extend(above_comments)
+
section_output.append(self._add_comments(from_comments,
self._wrap(import_start + as_imports[from_import])))
diff --git a/test_isort.py b/test_isort.py
index 51b34357..bdd4453c 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -2708,3 +2708,10 @@ def test_safety_excludes(tmpdir, enabled):
else:
assert file_names == {'.tox/verysafe.py', 'lib/python3.7/importantsystemlibrary.py', 'victim.py'}
assert not skipped
+
+
+def test_comments_not_removed_issue_576():
+ test_input = ('import distutils\n'
+ '# this comment is important and should not be removed\n'
+ 'from sys import api_version as api_version\n')
+ assert SortImports(file_contents=test_input).output == test_input