Skip to content

Commit

Permalink
Merge pull request #1299 from hyeonjames/issue-1276
Browse files Browse the repository at this point in the history
Issue #1276: Fix a bug that creates only one line after triple quotes
  • Loading branch information
timothycrosley committed Jul 9, 2020
2 parents 7daceb6 + a009c8d commit 2b57c9e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
19 changes: 5 additions & 14 deletions isort/output.py
Expand Up @@ -178,14 +178,12 @@ def sorted_imports(

if len(formatted_output) > imports_tail:
next_construct = ""
_in_quote: str = ""
tail = formatted_output[imports_tail:]

for index, line in enumerate(tail):
in_quote = _in_quote
should_skip, _in_quote, *_ = parse.skip_line(
should_skip, in_quote, *_ = parse.skip_line(
line,
in_quote=_in_quote,
in_quote="",
index=len(formatted_output),
section_comments=parsed.section_comments,
)
Expand All @@ -198,16 +196,9 @@ def sorted_imports(
continue
next_construct = line
break
elif not in_quote:
parts = line.split()
if (
len(parts) >= 3
and parts[1] == "="
and "'" not in parts[0]
and '"' not in parts[0]
):
next_construct = line
break
elif in_quote:
next_construct = line
break

if config.lines_after_imports != -1:
formatted_output[imports_tail:0] = ["" for line in range(config.lines_after_imports)]
Expand Down
18 changes: 18 additions & 0 deletions tests/test_isort.py
Expand Up @@ -120,6 +120,24 @@ def test_correct_space_between_imports() -> None:
test_output_other = isort.code(test_input_other)
assert test_output_other == "import sys\n\nprint('yo')\n"

test_input_inquotes = (
"import sys\n"
"@my_decorator('''hello\nworld''')\n"
"def my_method():\n"
" print('hello world')\n"
)
test_output_inquotes = api.sort_code_string(test_input_inquotes)
assert (
test_output_inquotes == "import sys\n"
"\n\n"
"@my_decorator('''hello\nworld''')\n"
"def my_method():\n"
" print('hello world')\n"
)
test_input_assign = "import sys\nVAR = 1\n"
test_output_assign = api.sort_code_string(test_input_assign)
assert test_output_assign == "import sys\n\nVAR = 1\n"


def test_sort_on_number() -> None:
"""Ensure numbers get sorted logically (10 > 9 not the other way around)"""
Expand Down

0 comments on commit 2b57c9e

Please sign in to comment.