[Regression] yapf version 0.20.0 Facebook style is broken in yapf verison 0.29.0
- Dominant language
- Python
- Stars
- 14k
- Forks
- 904
- PR merge metrics
- No merged PRs in 30d
Description
Related to #579
There's a YAPF demo being used officially in the README.md: https://yapf.now.sh/
Source code of the online demo: https://github.com/jpadilla/yapf-online
If we take a look at the Pipfile: https://github.com/jpadilla/yapf-online/blob/master/Pipfile
We can see the online demo is using yapf version 0.20.0.
This is what the "facebook" style looks like in 0.20.0:

Notice that in the yapf-formatted code (below), the array list of dictionary entries is neatly split, and there is no trailing comma in the list.
```
x = {
'a': [
{
'a': {
'a': 37,
'b': 42,
'c': 927
},
'b': 42,
'c': 927
}, {
'a': 37,
'b': 42,
'c': 927
}, {
'a': 37,
'b': 42,
'c': 927
}
]
}
y = 'hello ' 'world'
z = 'hello ' + 'world'
a = 'hello {}'.format('world')
class foo(object):
def f(self):
return 37 * -2
def g(self, x, y=42):
return y
def f(a):
return 37 - a[42 - x:y**3]
```
I'm currently using yapf version 0.29.0, installed using Python 3.8.0 64-bit, through `python -m pip install yapf`. The "facebook" style used in yapf 0.29.0 is incorrectly formatted, as shown in the code below. The code is identical to the code used in the online demo:
```
x = {
'a':
[
{
'a': {
'a': 37,
'b': 42,
'c': 927
},
'b': 42,
'c': 927
},
{
'a': 37,
'b': 42,
'c': 927
},
{
'a': 37,
'b': 42,
'c': 927
},
]
}
y = 'hello ' 'world'
z = 'hello ' + 'world'
a = 'hello {}'.format('world')
class foo(object):
def f(self):
return 37 * -2
def g(self, x, y=42):
return y
def f(a):
return 37 - a[42 - x:y**3]
```
Notice how the array list of dictionary entries are formatted in a weird way, and I think this is a regression from what is essentially a neatly formatted code.
No yapf_test test cases were failing, and PEP8 did not care about the indentation layout of the array list. However, from a readability standpoint, near the closing bracket of the array list, you will see an incorrectly indented ], which is indented twice.
That is the main problem of this issue. There seems to be some inconsistent list formatting that, somehow, the test cases aren't catching.
Contributor guide
Assessment
This issue has not been assessed yet.