yapf is not compatible with PEP 8
- Dominant language
- Python
- Stars
- 14k
- Forks
- 904
- PR merge metrics
- No merged PRs in 30d
Description
Hi, thanks for the great tool.
In PEP 8, there is a style guide for whitespace in expressions when using [slice operators](https://www.python.org/dev/peps/pep-0008/#pet-peeves). It says:
> However, in a slice the colon acts like a binary operator, and should have equal amounts on either side (treating it as the operator with the lowest priority). In an extended slice, both colons must have the same amount of spacing applied. Exception: when a slice parameter is omitted, the space is omitted:
``` python
# Correct:
ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:]
ham[lower:upper], ham[lower:upper:], ham[lower::step]
ham[lower+offset : upper+offset]
ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)]
ham[lower + offset : upper + offset]
# Wrong:
ham[lower + offset:upper + offset]
ham[1: 9], ham[1 :9], ham[1:9 :3]
ham[lower : : upper]
ham[ : upper]
```
However, even I gave an option `--style pep8`, yapf fix the above correct code snippet into the following:
(by running `diff <(cat t.py) <(yapf --style pep8 t.py)`
``` diff
--- /proc/self/fd/14 2021-03-31 15:05:58.938191854 +0900
+++ /proc/self/fd/16 2021-03-31 15:05:58.934191830 +0900
@@ -1,5 +1,5 @@
ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:]
ham[lower:upper], ham[lower:upper:], ham[lower::step]
-ham[lower+offset : upper+offset]
-ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)]
-ham[lower + offset : upper + offset]
+ham[lower + offset:upper + offset]
+ham[:upper_fn(x):step_fn(x)], ham[::step_fn(x)]
+ham[lower + offset:upper + offset]
```
I think this is not compatible with PEP 8.
Could you please let me understand why this is not compatible with PEP 8? Maybe there are some reasons for this, or maybe this is a bug?
Thank you.
Contributor guide
Assessment
This issue has not been assessed yet.