yapf icon indicating copy to clipboard operation
yapf copied to clipboard

Is there a way to `ALLOW_MULTILINE_LISTS`?

Open ThereforeGames opened this issue 1 year ago • 1 comments

Hi,

Similar to ALLOW_MULTILINE_DICTIONARY_KEYS, I would like YAPF to preserve the formatting of list items that have been declared on individual lines, e.g.

def ui(self, gr):
  return [
	  gr.Textbox(label="Conditional statement 🡢 my_var", max_lines=1),
	  gr.Dropdown(label="Evaluation method 🡢 _is", choices=["==", "!=", "<", "<=", ">", ">="], value="=="),
	  gr.Checkbox(label="Invert evaluation such that a true statement will return false 🡢 _not"),
	  gr.Checkbox(label="Return true if any one of multiple conditions are true 🡢 _any")
  ]

As far as I can tell, the only ways to achieve this would be to adjust the COLUMN_LIMIT (which would have side effects) or to wrap this block in # yapf: disable / enable comments. Is there a cleaner solution?

Thank you. Love your formatter.

ThereforeGames avatar May 13 '24 15:05 ThereforeGames

Oops, just noticed this is a dupe of https://github.com/google/yapf/issues/1209#issuecomment-1995750350 .

The simple workaround there works fine; just add a trailing comma to the list.

Still, I think a dedicated ALLOW_MULTILINE_LISTS option would be ideal, so I'll leave this open as a suggested feature enhancement. It's fairly unintuitive (at least to me) that a trailing comma would bypass the line concatenation rules.

ThereforeGames avatar May 13 '24 16:05 ThereforeGames