-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4068] Fix: --line-ranges dedents a # fmt: off in the middle of a decorator #4084
Conversation
Thanks! cc @yilei |
Thank you for the PR, the change looks good to me. (My original thought would be to add extra info in the |
CHANGES.md
Outdated
@@ -8,7 +8,8 @@ | |||
|
|||
### Stable style | |||
|
|||
<!-- Changes that affect Black's stable style --> | |||
- Fix bug where `# fmt: off` automatically dedents even when it is not within the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Fix bug where `# fmt: off` automatically dedents even when it is not within the | |
- Fix bug where `# fmt: off` automatically dedents when used with the `--line-ranges` option even when it is not within the |
It's good to explicitly mention the name of the option, especially since it is new.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for bringing it to my attention. I will make sure to take note of it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The requested modifications above have been completed.
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?