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

fmt: skip is required at the line which follows the one incorrectly formatted #4366

Open
mgoral opened this issue May 17, 2024 · 0 comments · May be fixed by #4380
Open

fmt: skip is required at the line which follows the one incorrectly formatted #4366

mgoral opened this issue May 17, 2024 · 0 comments · May be fixed by #4380
Labels
F: fmtskip fmt: skip implementation T: bug Something isn't working

Comments

@mgoral
Copy link

mgoral commented May 17, 2024

Hello, I believe I have found a bug in how black handles fmt: skip. Consider the following snippet:

t = (
    {"foo": "very long string", "bar": "another very long string", "baz": "we should run out of space by now"},
    {"foo": "bar"},
)

Without any changes, the line with first dictionary is 114 characters long and should be reformatted by black, which has a default line length limit set to 88 characters.. Second line is only 18 characters long and should be left intact.

Now, if I wanted to preserve formatting in this snippet, I believe I should add fmt: skip after the first dictionary:

t = (
    {"foo": "very long string", "bar": "another very long string", "baz": "we should run out of space by now"},  # fmt: skip
    {"foo": "bar"},
)

But this snippet is reformatted by black to:

t = (
    {
        "foo": "very long string",
        "bar": "another very long string",
        "baz": "we should run out of space by now",
    },  # fmt: skip
    {"foo": "bar"},
)

To prevent formatting of first dictionary, I have to add fmt: skip to both dictionaries:

t = (
    {"foo": "very long string", "bar": "another very long string", "baz": "we should run out of space by now"},  # fmt: skip
    {"foo": "bar"},  # fmt: skip
)

or surround the first dictionary with fmt: off - fmt:on:

t = (
    # fmt: off
    {"foo": "very long string", "bar": "another very long string", "baz": "we should run out of space by now"},
    # fmt: on
    {"foo": "bar"},
)

I'm using the following version, installed with pipx on Debian Trixie (current testing):

$ black --version
black, 24.4.2 (compiled: yes)
Python (CPython) 3.11.9
@mgoral mgoral added the T: bug Something isn't working label May 17, 2024
@JelleZijlstra JelleZijlstra added the F: fmtskip fmt: skip implementation label May 17, 2024
@devshah9 devshah9 linked a pull request Jun 15, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: fmtskip fmt: skip implementation T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants