Repository navigation
Conversation
Assisted-by: OpenAI Codex
There was a problem hiding this comment.
Copilot review overview
🟢 Approved
The implementation addresses both affected processing paths with comprehensive regression coverage and no unresolved issues found.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes multiline isort: split handling so complete import statements remain intact and stable.
Changes:
- Reads complete imports before applying split boundaries.
- Preserves split-marked continuation lines verbatim.
- Adds regression coverage for multiline, nested, CRLF, and float-to-top cases.
| File | Description |
|---|---|
isort/core.py |
Handles complete import statements during sorting and float-to-top preprocessing. |
isort/parse.py |
Preserves imports containing split directives on continuation lines. |
tests/unit/test_regressions.py |
Adds comprehensive regressions for issue #2680. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Assisted-by: OpenAI Codex
|
Synced with main Fresh full-unit result: 683 passed, 5 existing skips, and the same 3 Windows/environment failures independently reproduced on the unmodified current base. Coverage is 99.24%, with core/parse at 100% including branches. Ruff, formatting, flake8, Bandit, Linux-targeted mypy and clean-export package checks passed. The updated PR body lists the exact limitations; no cross-platform CI success is claimed. Assisted by OpenAI Codex. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2682 +/- ##
=======================================
Coverage 99.39% 99.40%
=======================================
Files 40 40
Lines 3317 3372 +55
Branches 716 726 +10
=======================================
+ Hits 3297 3352 +55
Misses 12 12
Partials 8 8 🚀 New features to boost your workflow:
|
DanielNoord
left a comment
There was a problem hiding this comment.
Please have a look at the AI review.
| if not part.lstrip().startswith(IMPORT_START_IDENTIFIERS): | ||
| break |
There was a problem hiding this comment.
Removed the added continuation reader as part of the smaller revision requested by Daniel. The existing upstream reader again keeps semicolon/backslash continuations together. Added the exact example as a regression in both modes: both failed on 5a2c9da, and both now produce valid, idempotent Python. The focused selection passes all 19 cases from source and the installed wheel.
| in_quote = _scan_quotes(line, stripped_line, in_quote) | ||
| is_code = not (in_quote or was_in_quote) | ||
| if is_code and stripped_line.startswith(IMPORT_START_IDENTIFIERS): | ||
| line, _ = _read_import_statement(line, input_stream) |
There was a problem hiding this comment.
Removed the added reader/iterator and restored upstream's ordinary continuation and quote-state handling. The exact multiline-string example is now covered with and without float_to_top; both failed on 5a2c9da and now pass without changing the string contents. The fix is scoped to the original closing-parenthesis split case, with all 19 focused regressions/controls passing from source and the installed wheel.
|
Similar to #2728 I am afraid this is getting a bit out of hand for the relative edge case we are fixing here. Isn't there a more minimal approach we can take here? Perhaps by not fixing all issues but at least making behaviour stable. |
|
Agreed. I reduced this to the original #2680 closing-parenthesis-line case. The general continuation reader and float-to-top iterator are removed; the production diff against f5b5649 is now 31 changed lines (previously 106), using the existing parser. The existing float-to-top state updates are also simplified to satisfy the complexity check without adding a new parser or helper. The previous broader guarantees for split directives at arbitrary positions inside imports are no longer proposed. The closing line stays with the section being parsed, the marked import is retained, and the normal processing pass treats it as a boundary. Both new review examples now produce valid, idempotent Python in both modes; they accounted for four failures on the preceding PR head. Validation: 19 focused cases pass from source and the verified installed wheel; 793 unit tests and 3 local property/integration tests pass, with 6 existing skips. Core and parse retain 100% statement/branch coverage, and configured lint/type/package checks pass. The title and description now reflect the smaller scope. |


Fixes #2680.
With
float_to_top=True, a parenthesized import ending in) # isort: splitcan leave a stray closing parenthesis in the output. Keep that closing line in the section being parsed, retain the marked import through the existing continuation collector, and use it as a boundary during normal processing. The marked import stays intact, and formatting the output again is stable.Following @DanielNoord's request, this revision removes the added general continuation reader and float-to-top iterator. The production diff against
f5b5649fis now 31 changed lines acrosscore.pyandparse.py(previously 106). Upstream's ordinary continuation and quote handling is retained. The existing float-to-top state updates are simplified without adding a new parser or helper. This also removes the two new semicolon/backslash and multiline-string regressions reported in review.The scope is the original closing-parenthesis-line case. The previous broader handling of split directives at arbitrary positions inside imports is no longer proposed; those upstream edge cases remain outside this fix.
Validation on Windows / CPython 3.13.15 in the dedicated task environment:
core.pyandparse.pyare 100%, including branches.0.0.0.dev0because it lacks Git metadata; installed core/parse hashes match that export.Compiled wheels, downstream repository clones, native Windows mypy and other Python/OS runs were not repeated locally. Updated remote CI is tracked separately.
AI assistance: revised and validated with OpenAI Codex.