Preserve form feed blank lines#2565
Open
lin-hongkuan wants to merge 1 commit into
Open
Conversation
Thank you for creating this well-targeted change. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2565 +/- ##
=======================================
Coverage 99.16% 99.16%
=======================================
Files 41 41
Lines 3101 3103 +2
Branches 671 670 -1
=======================================
+ Hits 3075 3077 +2
Misses 14 14
Partials 12 12 🚀 New features to boost your workflow:
|
DanielNoord
reviewed
Jun 28, 2026
|
|
||
| ### Unreleased | ||
|
|
||
| - Preserve form feed characters when they appear on otherwise blank lines (#2562) |
Member
There was a problem hiding this comment.
Please remove this, we don't keep the changes here
Comment on lines
+194
to
+195
| def _is_removable_blank_line(line: str) -> bool: | ||
| return "\f" not in line and line.strip() == "" |
Member
There was a problem hiding this comment.
Why can't we use strip() here?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
str.splitlines()treats form feed (\f, U+000C) as a line boundary, so parsing a file with a form-feed-only blank line drops the character before output is generated. Later, the import-tail blank-line cleanup also treats anystrip()-empty line as removable.This changes parsing to split only on actual newline sequences (
\r\n,\r,\n) and keeps import-tail cleanup from removing blank lines that contain form feed. That preserves valid Python blank lines while keeping the existing cleanup for ordinary whitespace-only lines.fixes #2562
Tests:
py -3 -m pytest tests/unit/test_regressions.py::test_form_feed_blank_line_not_removed_issue_2562 tests/unit/test_api.py::test_sort_code_string_mixed_newlines tests/unit/test_isort.py::test_ensure_line_endings_are_preserved_issue_493 tests/unit/test_isort.py::test_line_endings_are_detected_ignoring_whitespace -qpy -3 -m pytest tests/unit/test_regressions.py tests/unit/test_api.py tests/unit/test_isort.py -qpy -3 -m ruff check isort/parse.py isort/output.py tests/unit/test_regressions.py --ignore PLC0207py -3 -m mypy isort/parse.py isort/output.pyNote: a full
tests/unitrun produced 569 passed / 5 skipped before failing 4 environment-dependent tests unrelated to this change (example profile/sort plugin entry points and a Windows diff fixture side effect).