Preserve trailing-comma layout when sorting reexports - #2605
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2605 +/- ##
==========================================
+ Coverage 99.43% 99.49% +0.06%
==========================================
Files 41 41
Lines 3159 3177 +18
Branches 685 688 +3
==========================================
+ Hits 3141 3161 +20
+ Misses 11 10 -1
+ Partials 7 6 -1 🚀 New features to boost your workflow:
|
DanielNoord
left a comment
There was a problem hiding this comment.
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 :)
4fda57b to
04780d4
Compare
|
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 |
|
I'm a bit pressed for time currently. To keep moving this forward I'll ask Copilot for an initial review. Please disregard if it is bogus, it tends to help me by doing an initial pass but of course it isn't always the quality we hope for. |
There was a problem hiding this comment.
Pull request overview
Preserves multiline trailing-comma layouts when sorting reexports under compatible profiles such as Black.
Changes:
- Detects multiline literals with trailing commas.
- Prevents eligible collections from collapsing to one line.
- Adds tuple/list regression and helper coverage.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
isort/literal.py |
Detects and preserves trailing-comma layouts. |
tests/unit/test_literal.py |
Tests formatting callbacks and bracket detection. |
tests/unit/test_regressions.py |
Covers short tuple/list __all__ reexports. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Summary
Preserve explicitly multiline
__all__collections with trailing commas when--sort-reexportsruns 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
__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.pyuv run ruff check isort/literal.py tests/unit/test_regressions.pyuv run mypy isort tests./scripts/done.shCloses #2578