Skip to content

Preserve multiline strings after semicolon continuations - #2839

Open
XueHua-s wants to merge 3 commits into
PyCQA:mainfrom
XueHua-s:issue/2837
Open

XueHua-s wants to merge 3 commits into
PyCQA:mainfrom
XueHua-s:issue/2837

Conversation

@XueHua-s

@XueHua-s XueHua-s commented Dec 3, 2026 •

Copy link
Copy Markdown

Fixes #2837.

When a backslash-continued import ends with a semicolon and opens a triple-quoted string, isort could reorder import-looking lines inside the string and leave actual imports after the closing quotes unsorted. The continuation scanner now carries the open quote into the next line. This also keeps # isort: split and # isort: off inside the string from becoming section boundaries in float_to_top mode.

The regression tests check the string content, the order of subsequent imports, and second-pass idempotence. Fourteen targeted cases failed on the base commit. All 22 targeted cases passed with the patch. The unit suite passed with 882 tests and two skips (99% coverage). isort, Ruff, flake8, Bandit and mypy checks passed. The frozen environment download timed out, so the test script ran with cached tools and UV_NO_SYNC=1.

@XueHua-s

XueHua-s commented Dec 3, 2026

Copy link
Copy Markdown
Author

Verification update for 78f5353. I was able to run uv sync --all-extras --frozen and rerun ./scripts/test.sh in the locked environment. The suite passed with 882 tests, 2 skips and 99% coverage. The targeted run passed all 86 cases, including the string regression, literal sorting and line-ending handling. The repository's lint and type checks also passed.

The follow-up commits handle end of input explicitly and share the existing newline inference logic across the parsers.

This branch has not been deployed

No deployments
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.

Preserve multiline strings after semicolon continuations

1 participant