google / google/yapf

Inconsistent output, expected no change

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

Description

Original `test.py`, should not be changed by yapf:
```py
from django.urls import reverse

class TestCase:

def test1(self):
self.client.post(reverse('auth_login'), {
'username': 'mockmock@mockmock.com',
'password': 'mockmock',
})

def test2(self):
self.client.post(reverse('auth_login'), {
'username': 'mockmock@mockmock.com',
'password': 'wrongwrongwrong',
})
```

Surprisingly, `python -m yapf test.py > test2.py` produces:
```py
from django.urls import reverse

class TestCase:

def test1(self):
self.client.post(reverse('auth_login'), {
'username': 'mockmock@mockmock.com',
'password': 'mockmock',
})

def test2(self):
self.client.post(
reverse('auth_login'), {
'username': 'mockmock@mockmock.com',
'password': 'wrongwrongwrong',
}
)
```
Note that the first line in each function had been identical but they end up formatted differently even though they did not violate the maximum line length or other style rules as far as I can see.

`git diff test.py test2.py`
```diff
--- a/test.py
+++ b/test2.py
@@ -10,7 +10,9 @@ class TestCase:
})

def test2(self):
- self.client.post(reverse('auth_login'), {
- 'username': 'mockmock@mockmock.com',
- 'password': 'wrongwrongwrong',
- })
+ self.client.post(
+ reverse('auth_login'), {
+ 'username': 'mockmock@mockmock.com',
+ 'password': 'wrongwrongwrong',
+ }
+ )
```

`.style.yapf`
```ini
[style]
based_on_style = yapf
column_limit = 115
indent_width = 4
dedent_closing_brackets = true
```

Python 3.8.3
yapf 0.30.0

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.