Skip to content

Commit d4ae7cc

Browse files
Add support for skipping parens
1 parent 7960bf7 commit d4ae7cc

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

isort/core.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,7 @@ def process(
227227
and stripped_line not in config.treat_comments_as_code
228228
):
229229
import_section += line
230-
elif (
231-
stripped_line.startswith(IMPORT_START_IDENTIFIERS)
232-
):
230+
elif stripped_line.startswith(IMPORT_START_IDENTIFIERS):
233231
contains_imports = True
234232

235233
new_indent = line[: -len(line.lstrip())]
@@ -272,9 +270,20 @@ def process(
272270
indent = new_indent
273271
import_section += import_statement
274272
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+
275282
while stripped_line.endswith("\\"):
276-
line += input_stream.readline()
277-
stripped_line = line.strip().split("#")[0]
283+
new_line = input_stream.readline()
284+
line += new_line
285+
stripped_line = new_line.strip().split("#")[0]
286+
278287
not_imports = True
279288

280289
if not_imports:

tests/unit/test_regressions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ def function():
10061006
import a
10071007
"""
10081008
assert isort.check_code(will_ignore_if_non_comment_continuation, show_diff=True)
1009-
1009+
10101010
yield_from_parens_should_be_ignored = """
10111011
def generator_function():
10121012
(
@@ -1015,4 +1015,3 @@ def generator_function():
10151015
)
10161016
"""
10171017
assert isort.check_code(yield_from_parens_should_be_ignored, show_diff=True)
1018-

0 commit comments

Comments
 (0)