Knob for keeping the first line of multi-line dictionary entries on the same line as the key
- Dominant language
- Python
- Stars
- 14k
- Forks
- 904
- PR merge metrics
- No merged PRs in 30d
Description
I often create dictionaries that store an instance of an object. I would initialize this dictionary as:
```python
my_dict = {
'key1': module.Foo(
keyword_arg_1=value_1,
keyword_arg_2=value_2,
keyword_arg_3=value_3,
keyword_arg_4=value_4,
),
'key2': module.Foo(
keyword_arg_1=value_1,
keyword_arg_2=value_2,
keyword_arg_3=value_3,
keyword_arg_4=value_4,
),
}
```
Currently, I use the following configuration:
```
[style]
based_on_style = pep8
column_limit = 100
dedent_closing_brackets = True
indent_dictionary_value = True
indent_width = 2
join_multiple_lines = False
spaces_before_comment = 1
split_before_logical_operator = True
each_dict_entry_on_separate_line = True
```
With the above configuration, yapf reformats my code such that the dictionary entries are all moved to the following line:
```python
'key1':
module.Foo(
keyword_arg_1=value_1,
keyword_arg_2=value_2,
keyword_arg_3=value_3,
keyword_arg_4=value_4,
),
'key2':
peripheral.VariableSpec(
keyword_arg_1=value_1,
keyword_arg_2=value_2,
keyword_arg_3=value_3,
keyword_arg_4=value_4,
),
```
I'd really like to keep the original style without having to mark every instance of this with a `# yapf: disable`. Is there any way to retain the original style with the current yapf knobs?
If not, would it make sense to add a knob to accomplish this?
Contributor guide
Assessment
This issue has not been assessed yet.