Skip to content

Preserve trailing-comma layout when sorting reexports - #2605

Open
PSR94 wants to merge 1 commit into
PyCQA:mainfrom
PSR94:issue/2578-preserve-reexport-trailing-comma
Open

Preserve trailing-comma layout when sorting reexports#2605
PSR94 wants to merge 1 commit into
PyCQA:mainfrom
PSR94:issue/2578-preserve-reexport-trailing-comma

Conversation

@PSR94

@PSR94 PSR94 commented Aug 2, 2026

Copy link
Copy Markdown

Summary

Preserve explicitly multiline __all__ collections with trailing commas when --sort-reexports runs under trailing-comma-aware formatting such as the Black profile.

Why this helps

This keeps sorted reexports stable with Black's magic trailing comma behavior, so short __all__ declarations that are intentionally one item per line are not collapsed after sorting.

Changes made

  • Detect when a source literal is multiline and ends with a trailing comma.
  • Preserve that multiline layout when the active config includes trailing commas.
  • Add regression coverage for short tuple-style and list-style __all__ exports.

Testing

  • uv run pytest tests/unit/test_regressions.py -k '2578 or 2280'
  • uv run pytest tests/unit/test_isort.py -k 'reexport_multiline'
  • uv run ruff format --check isort/literal.py tests/unit/test_regressions.py
  • uv run ruff check isort/literal.py tests/unit/test_regressions.py
  • uv run mypy isort tests
  • ./scripts/done.sh

Closes #2578

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.36%. Comparing base (0145f77) to head (4fda57b).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2605      +/-   ##
==========================================
- Coverage   99.43%   99.36%   -0.07%     
==========================================
  Files          41       41              
  Lines        3159     3168       +9     
  Branches      685      687       +2     
==========================================
+ Hits         3141     3148       +7     
- Misses         11       12       +1     
- Partials        7        8       +1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DanielNoord DanielNoord left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think you can get full coverage on this? I have not looked at the code yet but we prefer all new code to be covered by tests :)

@PSR94
PSR94 force-pushed the issue/2578-preserve-reexport-trailing-comma branch from 4fda57b to 04780d4 Compare August 4, 2026 02:32
@PSR94

PSR94 commented Aug 4, 2026

Copy link
Copy Markdown
Author

Thanks for the review. I updated the PR to add coverage for the new literal formatting paths, including the formatting-function branch and the trailing-comma detection guard. I also reran uv run ruff format --check isort/literal.py tests/unit/test_literal.py tests/unit/test_regressions.py, uv run ruff check isort/literal.py tests/unit/test_literal.py tests/unit/test_regressions.py, uv run mypy isort tests, and ./scripts/done.sh; they are passing, and isort/literal.py reports 100% coverage locally.

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.

--sort-reexports does not retain trailing commas in short __all__ exports

2 participants