google / google/yapf

# yapf: disable does not preserve indent_width

Open
#912 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
14k
Forks
904
PR merge metrics
No merged PRs in 30d

Description

`# yapf: disable` does not preserve the indent width of the code to not be formatted, and applies `indent_width` instead. For example, in a python file using an indent of two spaces, `yapf` outputs a file with an indent width of four spaces in the disabled region:

```python
# yapf_disable_indent_width_bug.py
# yapf: disable
def dont_indent_me():
return
# yapf: enable
```

```python
python -m yapf -i yapf_disable_indent_width_bug.py
```

```python
# yapf_disable_indent_width_bug.py
# yapf: disable
def dont_indent_me():
return
# yapf: enable
```

Aside from throwing an error, this is probably the least awful thing to do when there is other code that yapf needs to format. That said it probably warrants noting that `# yapf: disable` will be disregarded wrt indent widths in its [readme section](https://github.com/google/yapf#why-does-yapf-destroy-my-awesome-formatting).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.