google / google/yapf

[Regression] yapf version 0.20.0 Facebook style is broken in yapf verison 0.29.0

Open
#800 0 comments 0 reactions 0 assignees View on GitHub
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:

![image](https://user-images.githubusercontent.com/6444116/72661408-975d0980-39a7-11ea-802b-588ab168b161.png)

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

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.