Skip to content
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

--line-ranges dedents a # fmt: off in the middle of a decorator #4068

Closed
yilei opened this issue Nov 21, 2023 · 0 comments · Fixed by #4084
Closed

--line-ranges dedents a # fmt: off in the middle of a decorator #4068

yilei opened this issue Nov 21, 2023 · 0 comments · Fixed by #4084
Labels
T: bug Something isn't working

Comments

@yilei
Copy link
Contributor

yilei commented Nov 21, 2023

Describe the bug

Given the following code:

@decor(
    a = 1,
    # fmt: off
    b = (2, 3),
    # fmt: on
)
def func():
    pass

Run black with

$ black --line-ranges=8-8 file.py

Line 8 is pass, and the file will be formatted to:

@decor(
    a = 1,
# fmt: off
    b = (2, 3),
    # fmt: on
)
def func():
    pass

Expected behavior

No formatting changes.

Environment

  • Black's version: [main]

Additional context

I'll take a look at this, I think we need to save additional info when code is converted to STANDALONE_COMMENT for # fmt: off/skip markers before we convert lines outside of --line-ranges= to STANDALONE_COMMENT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant