diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2020-09-19 21:35:22 -0700 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2020-09-19 21:35:22 -0700 |
commit | d4ae7cc8d75a130daa3e0e33b657c638131abaea (patch) | |
tree | 194c77962da64e0b23628ad1022244878963f151 | |
parent | 7960bf77bba40a492eb868f14b83068f0e6790f3 (diff) | |
download | isort-issue/1488/isort-mangling-lines-that-start-with-from.tar.gz |
Add support for skipping parensissue/1488/isort-mangling-lines-that-start-with-from
-rw-r--r-- | isort/core.py | 19 | ||||
-rw-r--r-- | tests/unit/test_regressions.py | 3 |
2 files changed, 15 insertions, 7 deletions
diff --git a/isort/core.py b/isort/core.py index 941ed7a1..db5cfcdf 100644 --- a/isort/core.py +++ b/isort/core.py @@ -227,9 +227,7 @@ def process( and stripped_line not in config.treat_comments_as_code ): import_section += line - elif ( - stripped_line.startswith(IMPORT_START_IDENTIFIERS) - ): + elif stripped_line.startswith(IMPORT_START_IDENTIFIERS): contains_imports = True new_indent = line[: -len(line.lstrip())] @@ -272,9 +270,20 @@ 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("\\"): - line += input_stream.readline() - stripped_line = line.strip().split("#")[0] + new_line = input_stream.readline() + line += new_line + stripped_line = new_line.strip().split("#")[0] + not_imports = True if not_imports: diff --git a/tests/unit/test_regressions.py b/tests/unit/test_regressions.py index 72e041da..e5a58685 100644 --- a/tests/unit/test_regressions.py +++ b/tests/unit/test_regressions.py @@ -1006,7 +1006,7 @@ def function(): import a """ assert isort.check_code(will_ignore_if_non_comment_continuation, show_diff=True) - + yield_from_parens_should_be_ignored = """ def generator_function(): ( @@ -1015,4 +1015,3 @@ def generator_function(): ) """ assert isort.check_code(yield_from_parens_should_be_ignored, show_diff=True) - |