Skip to content

Commit ea33a3e

Browse files
committed
format
1 parent 3ad62be commit ea33a3e

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

isort/core.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"{": "dict",
3232
}
3333

34+
3435
def process(
3536
input_stream: TextIO,
3637
output_stream: TextIO,
@@ -196,7 +197,11 @@ def process(
196197
first_comment_index_end = index - 1
197198

198199
was_in_quote = bool(in_quote)
199-
if not is_module_dunder(stripped_line) and (not stripped_line.startswith("#") or in_quote) and ('"' in line or "'" in line):
200+
if (
201+
not is_module_dunder(stripped_line)
202+
and (not stripped_line.startswith("#") or in_quote)
203+
and ('"' in line or "'" in line)
204+
):
200205
char_index = 0
201206
if first_comment_index_start == -1 and (
202207
line.startswith('"') or line.startswith("'")
@@ -294,7 +299,12 @@ def process(
294299
dunder_statement = line
295300
if stripped_line.endswith(("\\", "[", '= """', "= '''")):
296301
# Handle multiline module dunder assignments.
297-
while stripped_line and not stripped_line.endswith("]") and stripped_line != '"""' and stripped_line != "'''":
302+
while (
303+
stripped_line
304+
and not stripped_line.endswith("]")
305+
and stripped_line != '"""'
306+
and stripped_line != "'''"
307+
):
298308
line = input_stream.readline()
299309
stripped_line = line.strip()
300310
dunder_statement += line

isort/parse.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,13 @@ def file_contents(contents: str, config: Config = DEFAULT_CONFIG) -> ParsedConte
195195
if is_module_dunder(line):
196196
dunder_statement = line
197197
if line.endswith(("\\", "[", '= """', "= '''")):
198-
while index < line_count and line and not line.endswith("]") and line != '"""' and line != "'''":
198+
while (
199+
index < line_count
200+
and line
201+
and not line.endswith("]")
202+
and line != '"""'
203+
and line != "'''"
204+
):
199205
line = in_lines[index]
200206
index += 1
201207
dunder_statement += "\n" + line

isort/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,6 @@ def exists_case_sensitive(path: str) -> bool:
7575

7676
MODULE_DUNDER_PATTERN = re.compile(r"^__.*__\s*=")
7777

78+
7879
def is_module_dunder(line: str) -> bool:
7980
return bool(MODULE_DUNDER_PATTERN.match(line))

tests/unit/test_isort.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3732,7 +3732,6 @@ def test_new_lines_are_preserved() -> None:
37323732

37333733

37343734
def test_forced_separate_is_deterministic_issue_774(tmpdir) -> None:
3735-
37363735
config_file = tmpdir.join("setup.cfg")
37373736
config_file.write(
37383737
"[isort]\n"
@@ -5618,6 +5617,7 @@ def test_dunders() -> None:
56185617
"""
56195618
assert isort.code(test_input) == expected_output
56205619

5620+
56215621
def test_multiline_dunders() -> None:
56225622
"""Test to ensure isort correctly handles multiline dunders"""
56235623
test_input = """from __future__ import division

0 commit comments

Comments
 (0)