google / google/yapf

Incorrect dict indentation inside nested context?

Open
#1,169 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
14k
Forks
904
PR merge metrics
No merged PRs in 30d

Description

Hi, I'm trying to adopt YAPF for a larger code base and am running into a few edge cases. Is there a configuration option to achieve the following desired output? Thanks!

Actual:

```python
batcher = embodied.Batcher(
sources=[generator] * self.config.batch_size,
workers=self.config.data_loaders, postprocess=lambda x: {
**self._convert_inps(x, self.train_devices), 'rng':
self._next_rngs(self.train_devices)}, prefetch_source=4)
```

Desired:

```python
batcher = embodied.Batcher(
sources=[generator] * self.config.batch_size,
workers=self.config.data_loaders,
postprocess=lambda x: {
**self._convert_inps(x, self.train_devices),
'rng': self._next_rngs(self.train_devices)},
prefetch_source=4)
```

pyproject.toml

```toml
[tool.yapf]
based_on_style = "pep8"
indent_width = 2
allow_multiline_lambdas = true
continuation_align_style = "FIXED"
continuation_indent_width = 4
dedent_closing_brackets = false
each_dict_entry_on_separate_line = false
spaces_around_power_operator = true
split_arguments_when_comma_terminated = true
split_before_closing_bracket = false
split_before_expression_after_opening_paren = true
split_before_first_argument = true
split_before_logical_operator = false
split_before_named_assigns = false
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the nested lambda and dictionary formatting using the Python example and the supplied pyproject.toml settings. Compare the actual and desired output, then inspect the formatter behavior for this nested context; done means the desired indentation is produced or the limitation is clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.