yapf icon indicating copy to clipboard operation
yapf copied to clipboard

Leave single argument with trailing comma on own line

Open alexreg opened this issue 3 years ago • 3 comments
trafficstars

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?

alexreg avatar Nov 16 '22 16:11 alexreg

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 avatar Jun 16 '23 18:06 Spitfire1900

@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.

alexreg avatar Jun 16 '23 21:06 alexreg

~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", )

Spitfire1900 avatar Jun 17 '23 12:06 Spitfire1900