yapf
yapf copied to clipboard
Preserve arguments list aligned to an opening bracket
I have the following complain. This
redis = await create_subprocess_exec("Redis", "/usr/local/bin/redis-server",
"--bind", str(host), "--port", str(redis_port))
becomes this:
redis = await create_subprocess_exec(
"Redis", "/usr/local/bin/redis-server", "--bind", str(host), "--port", str(redis_port)
)
I would like to keep the first variant (where I align code to opening bracket and line brakes are set by some logic), but cannot find proper setting, is that possible?
I have tried to modify split_before_named_assigns
, but this did not help...
I'm interested in this as well.
It looks like CONTINUATION_INDENT_WIDTH
should have some sort of alignment option, rather than just a value.
+1
+1
Aligning with the opening delimiter is supported by PEP8, and it is the de facto standard within much of the Python standard library. +1
Any comments / progress on this? I much prefer this style -- I really wish there were a YAPF option for it :-(
YAPF tends to prefer placing as many things on a single line as possible. When I test your example above, I'm not able to get that behavior (at least not with top-of-tree YAPF). You might want to look at SPLIT_BEFORE_FIRST_ARGUMENT
though.
I"m not the OP, but what I want is a lot of arguments (or parameters) to be formatted like this:
a_call_with_lots_of_arguments(arg1,
arg2,
arg3,
kwarg1=something,
kwarg2=something_else,
)
which YAPF wants to format like so:
a_call_with_lots_of_arguments(
arg1,
arg2,
arg3,
kwarg1=something,
kwarg2=something_else,
)
As I read PEP8, either of those two are acceptable, as well as:
a_call_with_lots_of_arguments(arg1, arg2, arg3, kwarg1=something,
kwarg2=something_else,
)
which I personally don't like -- but it would be nice if YAPF provided all three options. Maybe it does, but I couldn't find the magic incantation.
I think as of now, the pep8
style outputs what @prokher wanted:
redis = await create_subprocess_exec("Redis", "/usr/local/bin/redis-server",
"--bind", str(host), "--port", str(redis_port))
And for that to become this:
redis = await create_subprocess_exec(
"Redis", "/usr/local/bin/redis-server", "--bind", str(host), "--port", str(redis_port)
)
the setting split_before_expression_after_opening_paren
must be set to true (which is the default for yapf
style).