Skip to content

fix: keep one-per-line layout of short multiline __all__ under trailing-comma profiles - #2644

Closed
Manny7717 wants to merge 2 commits into
PyCQA:mainfrom
Manny7717:fix/reexports-preserve-multiline
Closed

fix: keep one-per-line layout of short multiline __all__ under trailing-comma profiles#2644
Manny7717 wants to merge 2 commits into
PyCQA:mainfrom
Manny7717:fix/reexports-preserve-multiline

Conversation

@Manny7717

Copy link
Copy Markdown

What

--sort-reexports rewrote a short multi-line __all__ (one element per line, trailing comma) into a single line whenever the sorted result happened to fit within line_length — even under --profile black, dropping the trailing comma and the one-per-line style that black itself preserves. Reported in #2578.

# before
__all__ = (
    "FirstClass",
    "SecondClass",
)
# after --sort-reexports --profile black
__all__ = ("FirstClass", "SecondClass")

Change

isort.literal now preserves the vertical block form when the original literal was multi-line AND the active config uses trailing commas (include_trailing_comma, set by the black/comma-style profiles). Single-line sources and default-config behavior are unchanged — the pre-existing tests encoding the collapse behavior for the default config still pass.

Tests

  • test_sort_reexports_preserves_short_multiline_all_issue_2578: the issue's repro stays one-per-line and sorted, trailing comma intact. Fails on the previous implementation (verified).
  • test_sort_reexports_keeps_short_single_line_all_issue_2578: single-line __all__ is sorted in place and stays single-line.
  • All existing reexport tests (incl. the black-stability fixpoint test) pass; full suite 623 passed, 4 pre-existing env-dependent failures unrelated to this change.

…ng-comma profiles

--sort-reexports rewrote short multi-line __all__ collections into a
single line whenever the sorted result fit within line_length, even
under profiles that set include_trailing_comma (e.g. black), dropping
the trailing comma and the one-per-line style black itself preserves.
Preserve the multi-line form when the source was multi-line and the
active config uses trailing commas; single-line sources and default
config behavior are unchanged. Closes PyCQA#2578
@Manny7717

Copy link
Copy Markdown
Author

Closing as a duplicate of #2605, which implements the same fix for the same issue (#2578) with the same mechanism — a preserve-trailing-comma flag threaded through the collection sorters, gated on include_trailing_comma. #2605 predates this PR (Aug 17 vs Aug 28) and is already under maintainer review, and I verified its head passes the full literal + reexport test suite locally. Deferring to it — thanks @PSR94 for the cleaner _has_trailing_comma formulation.

@Manny7717 Manny7717 closed this Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant