summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2019-12-23 23:17:08 -0800
committerTimothy Crosley <timothy.crosley@gmail.com>2019-12-23 23:17:08 -0800
commit7480464332b3a370561d945b099630ca780721ab (patch)
tree246020f1b39f12560ad985dec69eb97a168246a6
parent29af5bd59536a670eb3de3b087cdd1e07f0f58dd (diff)
downloadisort-7480464332b3a370561d945b099630ca780721ab.tar.gz
Fix line import continuation handling
-rw-r--r--isort/_future/_dataclasses.py1
-rw-r--r--isort/api.py26
2 files changed, 12 insertions, 15 deletions
diff --git a/isort/_future/_dataclasses.py b/isort/_future/_dataclasses.py
index f7f6bace..8e2ff41a 100644
--- a/isort/_future/_dataclasses.py
+++ b/isort/_future/_dataclasses.py
@@ -1,5 +1,6 @@
# type: ignore
# flake8: noqa
+# flake8: noqa
"""Backport of Python3.7 dataclasses Library
Taken directly from here: https://github.com/ericvsmith/dataclasses
diff --git a/isort/api.py b/isort/api.py
index 14602378..c39b1b58 100644
--- a/isort/api.py
+++ b/isort/api.py
@@ -216,21 +216,17 @@ def sort_imports(
import_section += line
elif stripped_line.startswith(IMPORT_START_IDENTIFIERS):
import_section += line
- if "(" in stripped_line and ")" not in stripped_line:
- nested_line = line
- nested_stripped_line = nested_line.strip().split("#")[0]
- while ")" not in nested_stripped_line:
- nested_line = input_stream.readline()
- nested_stripped_line = nested_line.strip()
- import_section += nested_line
-
- if stripped_line.endswith("\\"):
- nested_line = line
- nested_stripped_line = nested_line.strip()
- while nested_line and nested_stripped_line.endswith("\\"):
- nested_line = input_stream.readline()
- nested_stripped_line = nested_line.strip()
- import_section += nested_line
+ while stripped_line.endswith("\\") or ("(" in stripped_line and ")" not in stripped_line):
+ if stripped_line.endswith("\\"):
+ while stripped_line and stripped_line.endswith("\\"):
+ line = input_stream.readline()
+ stripped_line = line.strip().split("#")[0]
+ import_section += line
+ else:
+ while ")" not in stripped_line:
+ line = input_stream.readline()
+ stripped_line = line.strip().split("#")[0]
+ import_section += line
contains_imports = True
else: