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

Feature request: Respect # fmt: skip at the end of multi-line statements #3009

Open
goodside opened this issue Apr 11, 2022 · 1 comment
Open
Labels
F: fmtskip fmt: skip implementation T: enhancement New feature or request

Comments

@goodside
Copy link

goodside commented Apr 11, 2022

Is your feature request related to a problem? Please describe.

Consider the following un-blackened code:

d = {}
d["foo"] = """
An example of very long text inserted into a dictionary.
"""

Applying black to this code produces an output that I'd argue is strictly worse than the input:

d = {}
d[
    "foo"
] = """
An example of very long text inserted into a dictionary.
""" 

It's unclear to me whether this constitutes a bug in black, but regardless I'd expect to be able to disable black on this one statement by writing # fmt: skip as follows:

d = {}
d["foo"] = """
An example of very long text inserted into a dictionary.
"""  # fmt: skip

This does not seem to work — the line is wrapped exactly as before.

Describe the solution you'd like

Python statements whose final line is marked with # fmt: skip should not be reformatted even if the statement spans across multiple lines.

Describe alternatives you've considered

My current workaround is to use # fmt: off and # fmt: on, but this is suboptimal as it adds exactly as many lines as it saves, except when there are multiple consecutive statements affected.

Additional context

I'm using conda-installed black 21.12b0 on MacOS Big Sur 11.6.

@goodside goodside added the T: enhancement New feature or request label Apr 11, 2022
@ricardo-dematos
Copy link

ricardo-dematos commented Jan 4, 2023

This will be a hard one to accept and/or implement...

Looking to your example, it makes sense, but it somehow contradicts the idea that the line containing the directive # fmt: skip should be skipped, regardless of what it is. To allow the directive to be applied to a multi-line statement, means black must interpret what's formatting.

Though one this is... 🤔

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: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants