5

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?

jorgeh
  • 1,727
  • 20
  • 32

1 Answers1

4

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

stovfl
  • 14,998
  • 7
  • 24
  • 51
  • That did it, thanks. That said, I've found a weird edge case: When I try `CREDS_FILE = os.path.join(os.path.expanduser('~'), 'apis/super-secret-admin-creds.json')` it puts both arguments in a new line, indented with 4 spaces, instead of keeping the first argument in the same line and splitting the second one to a new line, with hanging indentation. I understand this is an edge case, but maybe you know if there's some other configuration I can set? – jorgeh Jul 12 '17 at 21:06
  • 1
    @jorgeh: The Logic here is _Split at '=' Sign_. Maybe this `SPLIT_BEFORE_NAMED_ASSIGNS` _Split named assignments onto individual lines._, but the behavior isn't clear at all. – stovfl Jul 13 '17 at 13:01
  • 1
    @jorgeh `SPLIT_BEFORE_FIRST_ARGUMENT` doesn't have any impact on getting hanging indentation for function parameters (with `yapf 0.27.0`). Did the behaviour change? – Russ May 05 '19 at 20:14
  • same in version `0.30.0` – Ron May 20 '20 at 14:58