Skip to content

Commit

Permalink
Ensure that split_on_trailing_comma works with as imports
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Jan 18, 2025
1 parent 1c8d963 commit e264241
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion isort/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def _with_from_imports(
):
do_multiline_reformat = True

if config.split_on_trailing_comma and module in parsed.trailing_commas:
if import_statement and config.split_on_trailing_comma and module in parsed.trailing_commas:
import_statement = wrap.import_statement(
import_start=import_start,
from_imports=from_import_section,
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -5576,6 +5576,17 @@ def test_split_on_trailing_comma() -> None:
assert output == expected_output


def test_split_on_trailing_comma_wih_as() -> None:
test_input = "from lib import (a as b,)"
expected_output = """from lib import a as b
"""

output = isort.code(test_input, split_on_trailing_comma=True)
assert output == expected_output

output = isort.code(expected_output, split_on_trailing_comma=True)
assert output == expected_output

def test_infinite_loop_in_unmatched_parenthesis() -> None:
test_input = "from os import ("

Expand Down

0 comments on commit e264241

Please sign in to comment.