summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2019-02-24 08:52:17 -0800
committerTimothy Crosley <timothy.crosley@gmail.com>2019-02-24 08:52:17 -0800
commit9465f0058091794bc464adade550c0e8b6640415 (patch)
tree378211690be4ff930e204d57bf114bff034aeb44
parent544916c45c01b884512a1876a2c4180cb5722fb5 (diff)
downloadisort-feature/fix-issue-762.tar.gz
Fix issue #762feature/fix-issue-762
-rw-r--r--isort/isort.py3
-rw-r--r--test_isort.py10
2 files changed, 11 insertions, 2 deletions
diff --git a/isort/isort.py b/isort/isort.py
index c15b3cb0..3e2db2af 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -854,7 +854,6 @@ class SortImports(object):
if self.import_index == -1:
self.import_index = self.index - 1
-
nested_comments = {}
import_string, comments, new_comments = self._strip_comments(line)
stripped_line = [part for part in self._strip_syntax(import_string).strip().split(" ") if part]
@@ -873,7 +872,7 @@ class SortImports(object):
line, comments, new_comments = self._strip_comments(self._get_line(), comments)
# Still need to check for parentheses after an escaped line
- if "(" in line.split("#")[0] and not self._at_end():
+ if "(" in line.split("#")[0] and not ")" in line.split("#")[0] and not self._at_end():
stripped_line = self._strip_syntax(line).strip()
if import_type == "from" and stripped_line and " " not in stripped_line and new_comments:
nested_comments[stripped_line] = comments[-1]
diff --git a/test_isort.py b/test_isort.py
index aafafceb..19fb0540 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -2742,3 +2742,13 @@ def test_inconsistent_relative_imports_issue_577():
'from ...eu import dignissim\n'
'from ...ex import metus\n')
assert SortImports(file_contents=test_input, force_single_line=True).output == test_input
+
+
+def test_unwrap_issue_762():
+ test_input = ('from os.path \\\n'
+ 'import (join, split)\n')
+ assert SortImports(file_contents=test_input).output == 'from os.path import join, split\n'
+
+ test_input = ('from os.\\\n'
+ ' path import (join, split)')
+ assert SortImports(file_contents=test_input).output == 'from os.path import join, split\n'