fix: keep comment-only lines inside from-import groups#2588
fix: keep comment-only lines inside from-import groups#2588l46983284-cpu wants to merge 11 commits into
Conversation
|
DeepSource was failing because the existing Moved the skip back onto |
ee1bc23 to
468d670
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2588 +/- ##
==========================================
- Coverage 99.30% 99.22% -0.09%
==========================================
Files 41 41
Lines 3153 3207 +54
Branches 681 696 +15
==========================================
+ Hits 3131 3182 +51
- Misses 14 15 +1
- Partials 8 10 +2 🚀 New features to boost your workflow:
|
|
Fixed flake8 E303 by removing one extra blank line before the #1852 regression test. No product change. |
|
Residual loop closeout (multi-stage A/C/D/B1/B2 + mechanical gate PASS):
No further product thrash planned; remaining secondary nits (as-only / all-comment-only) disclosed as ALLOW_WITH_NITS scope. |
Route comment-only members onto the first single-line import and fold them into combine_star star comments so PyCQA#1852 does not silently drop body comments on secondary emit paths. Fixes residual findings from multi-stage review on PyCQA#2588. Signed-off-by: Alex Chen <l46983284@gmail.com>
|
Quick update without the process noise from my last note: I fixed two edge cases on the current head: force_single_line was dropping body comments, and combine_star left orphan indented comments. Both have regression tests, and the original #1852 black-profile case still passes. No further product thrash planned from me. Happy to adjust if review wants a different default. |
DanielNoord
left a comment
There was a problem hiding this comment.
Please ensure the full patch has coverage :)
For the tests I'd prefer the style of the first test so making explicit what the final output looks like instead of using "..." in out. However, if the output is the same as the input please use something like assert isort.code(to_sort, profile="black", line_length=100) == to_sort
|
Thanks — I rewrote the #1852 tests to use explicit expected output (including the force_single_line case) and added coverage for the remaining from_body / inject branches. |
DanielNoord
left a comment
There was a problem hiding this comment.
Can you fix CI to pass? I'll have a look at this afterwards :)
Comment-only members of a parenthesised from-import were collapsed onto the opening import line as a single semicolon-joined comment. With the black profile that rewrote intentional WIP comments and produced lines that fail line-length checkers. Track those body comments separately and re-emit them as indented lines inside parenthesised wrapping; preserve the historical collapse for non-parenthesised wrap modes. Fixes PyCQA#1852 Signed-off-by: Alex Chen <l46983284@gmail.com>
Signed-off-by: Alex Chen <l46983284@gmail.com>
CI lint fails on `ruff format --check` for the new regression test strings (and blank-line spacing). Apply ruff format only; product behavior unchanged. Signed-off-by: Alex Chen <l46983284@gmail.com>
Route comment-only members onto the first single-line import and fold them into combine_star star comments so PyCQA#1852 does not silently drop body comments on secondary emit paths. Fixes residual findings from multi-stage review on PyCQA#2588. Signed-off-by: Alex Chen <l46983284@gmail.com>
Signed-off-by: Alex Chen <l46983284@gmail.com>
mypy attr-defined failed because isort.output only aliases add_to_line as with_comments and does not re-export it. Signed-off-by: Alex Chen <l46983284@gmail.com>
isort --profile hug --check failed on tests/unit/test_regressions.py because isort.comments must sort before isort.main. Signed-off-by: Alex Chen <l46983284@gmail.com>
Signed-off-by: Alex Chen <l46983284@gmail.com>
Fold single-line body comments via with_comments instead of orphan indented lines, and drain remaining body comments onto the last emitted statement when no grouped import_statement is built. Signed-off-by: Alex Chen <l46983284@gmail.com>
Pending opening/body comments now attach to the first emitted force_single line (plain or as). Single-line inject merges existing nested trailing comments instead of clobbering them. Signed-off-by: Alex Chen <l46983284@gmail.com>
7e0c2ce to
0e3cd7e
Compare
|
Rebased onto main (kept the new alias-comment regression), fixed the lint/format gap, and closed the from_body drops on as-only / force_single emit paths. Local unit suite + mypy/flake8/ruff/hug check are green on this tip. |
DanielNoord
left a comment
There was a problem hiding this comment.
We're missing coverage again.
Add ignore_comments and nested-merge cases for _inject_from_body_comments, plus force_single_line plain-before-as coverage so the pending-comment drain path is exercised. Signed-off-by: Alex Chen <l46983284@gmail.com>
|
Thanks — added coverage for the remaining from_body inject branches ( |
Summary
Comment-only lines inside a parenthesised
from … import (group were collapsed onto the opening import line as one semicolon-joined comment. With the black profile that rewrote intentional WIP comments and produced lines that fail line-length checkers.This change tracks those body comments separately. When parentheses are used, they are re-emitted as their own indented comment lines inside the group. Non-parenthesised wrap modes keep the historical collapse behaviour so existing cases such as issue 1396 stay stable.
Test plan
pytest tests/unit/test_regressions.py::test_comment_only_lines_in_from_import_group_issue_1852pytest tests/unit/test_regressions.py::test_incorrect_grouping_when_comments_issue_1396pytest tests/unit/test_regressions.py::test_comment_on_opening_line_of_aliased_import_does_not_movepytest tests/unit/test_isort.py tests/unit/test_regressions.py tests/unit/test_comments.py(331 passed, 1 skipped)Fixes #1852