yapf
yapf copied to clipboard
Leave single argument with trailing comma on own line
Right now, I don't believe there's a way to have yapf put a single argument to a function on its own line when there's a trailing comma. For example,
bar = foo(
"only item",
)
gets formatted as
bar = foo("only item",)
whereas I prefer it to remain as-is, given the presence of a trailing comma.
On the other hand, lines such as
bar = foo(
"first item",
"second item",
)
are left alone, as desired.
Have I missed a config setting for this behaviour, or is this feature not yet implemented?
Hmm. My assumption here is that this is because it is being treated like a Tuple of length 1 where this would be undesired behavior.
@Spitfire1900 Possibly, but even then it might be nice to maintain the line-spacing based on what is already written. Or least have an option for this.
~Away from computer, check if SPLIT_ARGUMENTS_WHEN_COMMA_TERMINATED does what you want.~
This is for function definitions, not function calls.
$ pipx run yapf --no-local-style --style="{SPLIT_ARGUMENTS_WHEN_COMMA_TERMINATED: true}" <<EOF
def test(hello, world,):
> pass
> bar = foo("only item",)
> EOF
def test(
hello,
world,
):
pass
bar = foo("only item", )