Skip to content

Commit c7afdcd

Browse files
Fix #1488: isort should never mangle non-import from statements
1 parent e2cc148 commit c7afdcd

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

isort/core.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -270,20 +270,6 @@ def process(
270270
indent = new_indent
271271
import_section += import_statement
272272
else:
273-
if not import_section and "(" in stripped_line:
274-
while ")" not in stripped_line:
275-
new_line = input_stream.readline()
276-
if not new_line:
277-
break
278-
279-
line += new_line
280-
stripped_line = new_line.strip().split("#")[0]
281-
282-
while stripped_line.endswith("\\"):
283-
new_line = input_stream.readline()
284-
line += new_line
285-
stripped_line = new_line.strip().split("#")[0]
286-
287273
not_imports = True
288274

289275
if not_imports:
@@ -320,6 +306,7 @@ def process(
320306
raw_import_section += line
321307
if not contains_imports:
322308
output_stream.write(import_section)
309+
323310
else:
324311
leading_whitespace = import_section[: -len(import_section.lstrip())]
325312
trailing_whitespace = import_section[len(import_section.rstrip()) :]
@@ -375,6 +362,34 @@ def process(
375362
output_stream.write(line)
376363
not_imports = False
377364

365+
if stripped_line and not in_quote and not import_section and not next_import_section:
366+
if stripped_line == "yield":
367+
while not stripped_line or stripped_line == "yield":
368+
new_line = input_stream.readline()
369+
if not new_line:
370+
break
371+
372+
output_stream.write(new_line)
373+
stripped_line = new_line.strip().split("#")[0]
374+
375+
if stripped_line.startswith("raise") or stripped_line.startswith("yield"):
376+
if "(" in stripped_line:
377+
while ")" not in stripped_line:
378+
new_line = input_stream.readline()
379+
if not new_line:
380+
break
381+
382+
output_stream.write(new_line)
383+
stripped_line = new_line.strip().split("#")[0]
384+
385+
while stripped_line.endswith("\\"):
386+
new_line = input_stream.readline()
387+
if not new_line:
388+
break
389+
390+
output_stream.write(new_line)
391+
stripped_line = new_line.strip().split("#")[0]
392+
378393
return made_changes
379394

380395

0 commit comments

Comments
 (0)