How to configure YAPF to use hanging indentation for long argument lists

6.4k Views Asked by At

I've using yapf to automatically format my python code. In general I'm very happy with it, but there's a style convention I can't figure out how to configure. When there's a long list of arguments inside a pair of parentheses, which expand beyond the max column_limit (e.g. 80), I'd like it to split them into separate lines, but keeping the indentation of the opening parenthesis if possible. For example:

def func(argument1, argument2, argument3, argument4, argument5, argument6, argument7):
    pass

should become

def func(argument1, 
         argument2, 
         argument3,
         argument4,
         argument5,
         argument6,
         argument7):
    pass

But I can only get it to do:

def func(
    argument1, 
    argument2, 
    argument3,
    argument4,
    argument5,
    argument6,
    argument7):
    pass

Anyone know if what I want is possible? How?

1

There are 1 best solutions below

4
On BEST ANSWER

Check this:

SPLIT_BEFORE_FIRST_ARGUMENT
If an argument / parameter list is going to be split, then split before the first argument.

yapf 0.16.2: Formatting style