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
Should # fmt: off
be allowed as an inline comment?
#790
Comments
#fmt: off
be allowed as an inline comment?# fmt: off
be allowed as an inline comment?
as a work-around for this, i use this snippet in my editor nowadays: __import__("pdb").set_trace() # FIXME which will be left as-is since it's a single statement. |
@wbolster That's handy, thanks! Separately the question still stands. I see two positions: First, yes should do this because most linters allow inline comments. This is a feature I assumed should work based on historical experience with things like flake8, pylint, etc. It's also helpful/handy for small inline things, like maybe a large comprehension that I'm using to test with I can bang Second, no, this isn't desirable because black is an opinionated formatter. It shouldn't make it easy to ignore (two lines to ignore a comment instead of an inline one). It's also likely this case is rare. I don't think clang-format allows inline ignores for a single line, and I haven't used yapf in three years. This is feature parity with auto-formatters which, as opposed to linters, operate on a larger scope (typically a block) than a specific line alone. I've mostly convinced myself that the not doing this is easier and probably more consistent than doing this, unless someone has a use case or wants to further support the opinion for doing this? I'll put a patch together if the feeling is this should be explored further. |
See also #798. |
Practically, using |
the intuitive (or least surprising) behaviour would be to leave the whole statement alone except for required reindentation (of each line of the statement). |
I'd like to give another use case. Sometiems I group long list of command line arguments in groups that makes sense, for example: cmd = [
'docker', 'run',
'--detach',
'--publish', '5432:5432',
'--env', 'POSTGRES_PASSWORD=postgres',
'--label', 'pg_testing',
'postgres:12',
] Which black turns into: cmd = [
'docker',
'run',
'--detach',
'--publish',
'5432:5432',
'--env',
'POSTGRES_PASSWORD=postgres',
'--label',
'pg_testing',
'postgres:12',
] I've love to be able to add a |
@tebeka for large multiline blocks, I find it tolerable to wrap the section in # fmt: off
cmd = [
'docker', 'run',
'--detach',
'--publish', '5432:5432',
'--env', 'POSTGRES_PASSWORD=postgres',
'--label', 'pg_testing',
'postgres:12',
]
# fmt: on not sure if you knew about, but in general, I would still like inline |
lo and behold: cmd = [
*["docker", "run"],
*["--detach"],
*["--publish", "5432:5432"],
*["--env", "POSTGRES_PASSWORD=postgres"],
*["--label", "pg_testing"],
*["postgres:12"],
] this creative use of ‘splat’ syntax (list unpacking) gives the same result, and in fact, future me will likely deny that i suggested this at all. 😉 |
We now support |
Sometimes I drop a
import ipdb; ipdb.set_trace()
line into a file when I'm debugging.black
is super fast and cheerfully reformats this instantly on save to a multi-line:I ignored this a few times, and then figured I would write
import ipdb; ipdb.set_trace() # fmt: off
. I was surprised thatblack
cheerfully (and again I want to stress this, super fast!) reformatted this into:It kept the comment, spacing, everything. Such a good formatter!
But I wonder, could we allow an inline
# fmt: off
for this situation? Or for other one-liners or function definitions do avoid the need to wrap# fmt: off
/# fmt: on
blocks?The text was updated successfully, but these errors were encountered: