Skip to content

Commit

Permalink
Restore fix for issue #651
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Feb 3, 2018
1 parent 20fe5cd commit ff24354
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 1 addition & 2 deletions isort/isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ def by_module(line):
parts = line.split()
if len(parts) >= 3 and parts[1] == '=' and "'" not in parts[0] and '"' not in parts[0]:
next_construct = line
break

if self.config['lines_after_imports'] != -1:
self.out_lines[imports_tail:0] = ["" for line in range(self.config['lines_after_imports'])]
Expand Down Expand Up @@ -821,8 +822,6 @@ def _skip_line(self, line):
self._in_quote = line[index]
elif line[index] == "#":
break
elif line[index] not in (' ', '\t'):
break
index += 1

return skip_line or self._in_quote or self._in_top_comment
Expand Down
17 changes: 17 additions & 0 deletions test_isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -2342,3 +2342,20 @@ def test_escaped_parens_sort():
def test_is_python_file_ioerror(tmpdir):
does_not_exist = tmpdir.join('fake.txt')
assert is_python_file(str(does_not_exist)) is False


def test_to_ensure_imports_are_brought_to_top_issue_651():
test_input = ('from __future__ import absolute_import, unicode_literals\n'
'\n'
'VAR = """\n'
'multiline text\n'
'"""\n'
'\n'
'from __future__ import unicode_literals\n'
'from __future__ import absolute_import\n')
expected_output = ('from __future__ import absolute_import, unicode_literals\n'
'\n'
'VAR = """\n'
'multiline text\n'
'"""\n')
assert SortImports(file_contents=test_input).output == expected_output

0 comments on commit ff24354

Please sign in to comment.