From c7afdcd1353e33c7a1fe67e507bb6b5150e8ddfa Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Sun, 20 Sep 2020 15:18:39 -0700 Subject: [PATCH] Fix #1488: isort should never mangle non-import from statements --- isort/core.py | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/isort/core.py b/isort/core.py index db5cfcdf6..d1e945d48 100644 --- a/isort/core.py +++ b/isort/core.py @@ -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: @@ -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()) :] @@ -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