[4068] Fix: --line-ranges dedents a # fmt: off in the middle of a decorator #4084
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
When transforming
fmt:off
into standalone comments, a new node is generated forfmt:off
, and in this procedure, the initial indentation offmt:off
is not retained. Black code consistently convertsfmt:off/on
into standalone comments before proceeding with additional formatting. Consequently, the formatting offmt:off
is disrupted, even when it is not within the specified line range.I addressed this issue by retaining the indentation of
fmt:off
and incorporating it into the prefix of the new nodeAdditionally, I observed that black consistently formats comments, regardless of whether
fmt:off
is present or if the comments fall outside the specified line range.I refrained from raising an issue for this because I was uncertain whether it was intended behaviour or not.
Fixes: #4068
Checklist
CHANGES.md
if necessary?