Preserve blank lines before fmt-off classes#5238
Open
sjh9714 wants to merge 1 commit into
Open
Conversation
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.
Description
Fixes #5225.
When a top-level class starts inside a
# fmt: offblock after an import, theconverted block looks like a standalone comment to the empty-line tracker. This caused
Black to keep only one blank line instead of the two required before a top-level class.
Preserve the converted block's original
classtoken when deciding import separation.The change is limited to a new preview feature, so stable formatting remains unchanged,
and a focused fixture covers the reported input.
Testing
.venv/bin/pytest tests/test_format.py -k preview_fmt_off_class_blank_lines -q.venv/bin/pytest tests/test_format.py -qenv -u NO_COLOR .venv/bin/pytest -qenv -u NO_COLOR .venv/bin/pre-commit run mypy --files src/black/lines.py src/black/mode.pyenv -u NO_COLOR .venv/bin/tox -e run_self.venv/bin/tox -e generate_schemaenv -u NO_COLOR .venv/bin/pre-commit run --all-filespassed every hook exceptrepository-wide mypy, which reports an unchanged
action/main.pytomllibignore/stub mismatch under Python 3.14. The targeted mypy hook above passes for both
changed Python modules.
Note: I used Codex while preparing this change, reviewed the final diff, and ran the
checks listed above locally.
Checklist - did you ...
--previewstyle, following the stability policy?CHANGES.mdif necessary?