summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2015-02-05 11:59:33 -0500
committerTimothy Crosley <timothy.crosley@gmail.com>2015-02-05 11:59:33 -0500
commitbd8b38542d5645762f1d0ecdde4f34da6b32ef02 (patch)
treeeb90c717aad3d14112328926aa9bdeaeaef690cb
parent6f4b5cf3f2185e7d4eb0d74549198fdb16e609d5 (diff)
downloadisort-bd8b38542d5645762f1d0ecdde4f34da6b32ef02.tar.gz
Fix issue #238
-rw-r--r--isort/isort.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/isort/isort.py b/isort/isort.py
index 038cd3d0..f8dbd108 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -620,6 +620,7 @@ class SortImports(object):
while not self._at_end():
line = self._get_line()
skip_line = self._skip_line(line)
+ on_first_import = False
if line in self._section_comments and not skip_line:
if self.import_index == -1:
@@ -650,6 +651,7 @@ class SortImports(object):
line = line.replace("\t", " ")
if self.import_index == -1:
self.import_index = self.index - 1
+ on_first_import = True
nested_comments = {}
import_string, comments, new_comments = self._strip_comments(line)
@@ -706,7 +708,8 @@ class SortImports(object):
if comments:
self.comments['from'].setdefault(import_from, []).extend(comments)
last = self.out_lines and self.out_lines[-1].rstrip() or ""
- if last.startswith("#") and not last.endswith('"""') and not last.endswith("'''"):
+ if (not on_first_import and last.startswith("#") and not last.endswith('"""') and not
+ last.endswith("'''")):
self.comments['above']['from'].setdefault(import_from, []).append(self.out_lines.pop(-1))
if root.get(import_from, False):
root[import_from].update(imports)
@@ -718,6 +721,7 @@ class SortImports(object):
self.comments['straight'][module] = comments
comments = None
last = self.out_lines and self.out_lines[-1].rstrip() or ""
- if last.startswith("#") and not last.endswith('"""') and not last.endswith("'''"):
+ if (not on_first_import and last.startswith("#") and not
+ last.endswith('"""') and not last.endswith("'''")):
self.comments['above']['from'][module] = self.out_lines.pop(-1)
self.imports[self.place_module(module)][import_type].add(module)