black
black copied to clipboard
Feature request: Respect `# fmt: skip` at the end of multi-line statements
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.
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... 🤔