Should python function argument definitions be indented 4 or 8 spaces?
YAPF recently changed from indenting like
def f(
a: str,
b: str,
) -> None:
pass
to:
def f(
a: str,
b: str,
) -> None:
pass
I thought the first way was correct, but looking at the style guide more, I'm not actually sure what the correct behavior is. The indentation section doesn't say anything about function arguments in a def statement. The type annotation line breaking section does have examples, but those follow Google's internal 2-space indentation style instead of the external 4-space style.
2nd one is correct examples might be similar to these: https://google.github.io/styleguide/pyguide.html#32-line-length https://google.github.io/styleguide/pyguide.html#34-indentation
Neither of those sections have examples with def statements, so I don't think they point towards either way of indenting a def statement. Note that the second way can be really hard to read if the closing parenthesis isn't on a new line, since it's hard to see where the args end and the body starts:
def f(
a: str,
b: str) -> str:
c: str = 'foo'
return f'{a}: {b} - {c}'
Actually, I prefer using def like:
def f(a: Text,
b: Text): # Align with 'a' at 1st line.
...