Skip to content

Commit

Permalink
Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Jul 9, 2020
1 parent e00418b commit 2e21943
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ Changelog
=========

NOTE: isort follows the [semver](https://semver.org/) versioning standard.

### 5.0.6 July 8, 2020
- Fixed #1302: comments and --trailing-comma can generate invalid code

### 5.0.5 July 7, 2020
- Fixed #1285: packaging issue with bundling tests via poetry.
- Fixed #1284: Regression when sorting `.pyi` files from CLI using black profile.
Expand Down
4 changes: 3 additions & 1 deletion isort/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def line(content: str, line_separator: str, config: Config = DEFAULT_CONFIG) ->
):
line_parts = re.split(exp, line_without_comment)
if comment:
_comma_maybe = "," if config.include_trailing_comma else ""
_comma_maybe = (
"," if (config.include_trailing_comma and config.use_parentheses) else ""
)
line_parts[-1] = f"{line_parts[-1].strip()}{_comma_maybe} #{comment}"
next_line = []
while (len(content) + 2) > (
Expand Down
19 changes: 19 additions & 0 deletions tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,22 @@ def test_ensure_new_line_before_comments_mixed_with_ensure_newline_before_commen
"""
assert isort.code(test_input, profile="black") == test_input
assert isort.code(test_input, profile="black", force_sort_within_sections=True) == test_input


def test_trailing_comma_doesnt_introduce_broken_code_with_comment_and_wrap_issue_1302():
"""Tests to assert the combination of include_trailing_comma and a wrapped line doesnt break.
See: https://github.com/timothycrosley/isort/issues/1302.
"""
assert (
isort.code(
"""
from somewhere import very_very_very_very_very_very_long_symbol # some comment
""",
line_length=50,
include_trailing_comma=True,
)
== """
from somewhere import \\
very_very_very_very_very_very_long_symbol # some comment
"""
)

0 comments on commit 2e21943

Please sign in to comment.