Skip to content

Commit 8b83d56

Browse files
Fix handling of yield and raise statements in import identification
1 parent 0b07215 commit 8b83d56

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

isort/identify.py

+19
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ def imports(
5757
if skipping_line:
5858
continue
5959

60+
stripped_line = line.strip().split("#")[0]
61+
if stripped_line.startswith("raise") or stripped_line.startswith("yield"):
62+
if stripped_line == "yield":
63+
while not stripped_line or stripped_line == "yield":
64+
try:
65+
index, next_line = next(indexed_input)
66+
except StopIteration:
67+
break
68+
69+
stripped_line = next_line.strip().split("#")[0]
70+
while stripped_line.endswith("\\"):
71+
try:
72+
index, next_line = next(indexed_input)
73+
except StopIteration:
74+
break
75+
76+
stripped_line = next_line.strip().split("#")[0]
77+
continue
78+
6079
line, *end_of_line_comment = line.split("#", 1)
6180
statements = [line.strip() for line in line.split(";")]
6281
if end_of_line_comment:

0 commit comments

Comments
 (0)