google / yapf

A formatter for Python files
Apache License 2.0
13.79k stars 892 forks source link

Prevent double indenting when splitting function parameters in if or with #982

Open char101 opened 2 years ago

char101 commented 2 years ago

Hi, is this supported by yapf configuration if I want to prevent the function parameters from being indented twice in this case:

if func(
    a,
    b,
):
    pass

Output:

if func(
        a,
        b,
):
    pass

Desired output:

if func(
    a,
    b,
):
    pass

I can get the output that I want by changing https://github.com/google/yapf/blob/main/yapf/yapflib/format_decision_state.py#L980 from

return token_indent + style.Get('CONTINUATION_INDENT_WIDTH')

to

return token_indent

But I wonder if this is configurable.

sinoroc commented 2 years ago

Looks like I have the opposite issue: https://github.com/google/yapf/issues/843 ; maybe you find something helpful in this ticket and its links.

NoamNol commented 2 years ago

It's only when CONTINUATION_INDENT_WIDTH = 4 ): DEDENT_CLOSING_BRACKETS = true solved it in function definition but not in function call

quancs commented 4 months ago

mark