Skip to content

Commit

Permalink
Fix #1488: isort should never mangle non-import from statements
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Sep 20, 2020
1 parent e2cc148 commit c7afdcd
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions isort/core.py
Expand Up @@ -270,20 +270,6 @@ def process(
indent = new_indent
import_section += import_statement
else:
if not import_section and "(" in stripped_line:
while ")" not in stripped_line:
new_line = input_stream.readline()
if not new_line:
break

line += new_line
stripped_line = new_line.strip().split("#")[0]

while stripped_line.endswith("\\"):
new_line = input_stream.readline()
line += new_line
stripped_line = new_line.strip().split("#")[0]

not_imports = True

if not_imports:
Expand Down Expand Up @@ -320,6 +306,7 @@ def process(
raw_import_section += line
if not contains_imports:
output_stream.write(import_section)

else:
leading_whitespace = import_section[: -len(import_section.lstrip())]
trailing_whitespace = import_section[len(import_section.rstrip()) :]
Expand Down Expand Up @@ -375,6 +362,34 @@ def process(
output_stream.write(line)
not_imports = False

if stripped_line and not in_quote and not import_section and not next_import_section:
if stripped_line == "yield":
while not stripped_line or stripped_line == "yield":
new_line = input_stream.readline()
if not new_line:
break

output_stream.write(new_line)
stripped_line = new_line.strip().split("#")[0]

if stripped_line.startswith("raise") or stripped_line.startswith("yield"):
if "(" in stripped_line:
while ")" not in stripped_line:
new_line = input_stream.readline()
if not new_line:
break

output_stream.write(new_line)
stripped_line = new_line.strip().split("#")[0]

while stripped_line.endswith("\\"):
new_line = input_stream.readline()
if not new_line:
break

output_stream.write(new_line)
stripped_line = new_line.strip().split("#")[0]

return made_changes


Expand Down

0 comments on commit c7afdcd

Please sign in to comment.