google / yapf

A formatter for Python files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unecessary line break and incorrect indentation?

danijar opened this issue · comments

Hi, thanks so much for developing YAPF! I'm running into a case where the formatting does not do what I would expect. Below is a reproducing example, where I would like to avoid the line break after {. Moreover, even if there was a line break after { then I would still expect the following lines (starting with **) to be indented by two additional spaces.

Maybe it's an issue with split_before_expression_after_opening_paren that correctly breaks after the first ( but then unnecessarily also breaks after the first {?

Is there a configuration option I can add to achieve the desired behavior or would this be considered a bug? Thanks!

Actual output:

foo = lambda lorem, ipsum, dolor, sit, amet, fn=foo, **kw: (
    fn({
    **lorem,
    **ipsum}, dolor, sit, amet, **kw))

Desired output:

foo = lambda lorem, ipsum, dolor, sit, amet, fn=foo, **kw: (
    fn({**lorem, **ipsum}, dolor, sit, amet, **kw))

pyproject.toml

[tool.yapf]
based_on_style = "pep8"
indent_width = 2
allow_multiline_lambdas = true
continuation_align_style = "FIXED"
continuation_indent_width = 4
split_before_closing_bracket = false
split_before_expression_after_opening_paren = true
split_before_first_argument = true
dedent_closing_brackets = false

I noticed that the issue can be avoided with the each_dict_entry_on_separate_line = false option, although I'm still wondering why the ** lines were not properly indented above.