Increase penalty for splitting after pseudo-paren.
diff --git a/CHANGELOG b/CHANGELOG
index 0681f94..89f4c6a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -13,6 +13,8 @@
- Add a small penalty for splitting before a closing bracket.
- Ensure that a space is enforced after we remove a pseudo-paren that's between
two names, keywords, numbers, etc.
+- Increase the penalty for splitting after a pseudo-paren. This could lead to
+ less readable code in some circumstances.
## [0.6.0] 2015-10-18
### Added
diff --git a/yapf/yapflib/format_decision_state.py b/yapf/yapflib/format_decision_state.py
index 3848c15..9608b23 100644
--- a/yapf/yapflib/format_decision_state.py
+++ b/yapf/yapflib/format_decision_state.py
@@ -303,6 +303,10 @@
# Calculate the split penalty.
penalty = current.split_penalty
+ if previous.is_pseudo_paren and previous.value == '(':
+ # Small penalty for splitting after a pseudo paren.
+ penalty += 50
+
# Add a penalty for each increasing newline we add.
last = self.stack[-1]
penalty += (style.Get('SPLIT_PENALTY_FOR_ADDED_LINE_SPLIT') *
diff --git a/yapf/yapflib/format_token.py b/yapf/yapflib/format_token.py
index 9f5999c..0e666c7 100644
--- a/yapf/yapflib/format_token.py
+++ b/yapf/yapflib/format_token.py
@@ -218,7 +218,9 @@
return pytree_utils.NodeName(self._node)
def __repr__(self):
- return 'FormatToken(name={0}, value={1})'.format(self.name, self.value)
+ msg = 'FormatToken(name={0}, value={1}'.format(self.name, self.value)
+ msg += ', pseudo)' if self.is_pseudo_paren else ')'
+ return msg
@property
def is_comment(self):
diff --git a/yapftests/reformatter_test.py b/yapftests/reformatter_test.py
index 997aae7..6dc37a0 100644
--- a/yapftests/reformatter_test.py
+++ b/yapftests/reformatter_test.py
@@ -1122,8 +1122,8 @@
""")
expected_formatted_code = textwrap.dedent("""\
a = foo.bar({'xxxxxxxxxxxxxxxxxxxxxxx'
- 'yyyyyyyyyyyyyyyyyyyyyyyyyy':
- baz[42]} + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
+ 'yyyyyyyyyyyyyyyyyyyyyyyyyy': baz[42]
+ } + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
'bbbbbbbbbbbbbbbbbbbbbbbbbb'
'cccccccccccccccccccccccccccccccc'
'ddddddddddddddddddddddddddddd')
@@ -1477,6 +1477,18 @@
def setUpClass(cls):
style.SetGlobalStyle(style.CreateChromiumStyle())
+ def testB25136704(self):
+ code = textwrap.dedent("""\
+ class f:
+
+ def test(self):
+ self.bbbbbbb[0][
+ 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
+ {'xxxxxx': 'yyyyyy'}] = cccccc.ddd('1m', '10x1+1')
+ """)
+ uwlines = _ParseAndUnwrap(code)
+ self.assertCodeEqual(code, reformatter.Reformat(uwlines))
+
def testB25165602(self):
code = textwrap.dedent("""\
def f():
@@ -1905,8 +1917,8 @@
}))
""")
expected_formatted_code = textwrap.dedent("""\
- instance = (aaaaaaa.bbbbbbb().ccccccccccccccccc().ddddddddddd({'aa':
- 'context!'}).eeeeeeeeeeeeeeeeeee({ # Inline comment about why fnord has the value 6.
+ instance = (aaaaaaa.bbbbbbb().ccccccccccccccccc().ddddddddddd(
+ {'aa': 'context!'}).eeeeeeeeeeeeeeeeeee({ # Inline comment about why fnord has the value 6.
'fnord': 6
}))
""")