Add a small penalty for splitting before a closing bracket.
diff --git a/CHANGELOG b/CHANGELOG
index b6eeff8..616d784 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -10,6 +10,7 @@
- Make sure that continuations from a compound statement are distinguished from
the succeeding line.
- Ignore preceding comments when calculating what is a "dictonary maker".
+- Add a small penalty for splitting before a closing bracket.
## [0.6.0] 2015-10-18
### Added
diff --git a/yapf/yapflib/unwrapped_line.py b/yapf/yapflib/unwrapped_line.py
index fe72d13..b238e46 100644
--- a/yapf/yapflib/unwrapped_line.py
+++ b/yapf/yapflib/unwrapped_line.py
@@ -465,6 +465,9 @@
if cur_token.value == '==':
# We would rather not split before an equality operator.
return split_penalty.STRONGLY_CONNECTED
+ if cur_token.ClosesScope():
+ # Give a slight penalty for splitting before the closing scope.
+ return 100
if prev_token.value in _TERM_OPERATORS or cur_token.value in _TERM_OPERATORS:
return 50
return 0
diff --git a/yapftests/reformatter_test.py b/yapftests/reformatter_test.py
index 314623c..68ce37b 100644
--- a/yapftests/reformatter_test.py
+++ b/yapftests/reformatter_test.py
@@ -1477,6 +1477,16 @@
def setUpClass(cls):
style.SetGlobalStyle(style.CreateChromiumStyle())
+ def testB25157123(self):
+ code = textwrap.dedent("""\
+ def ListArgs():
+ FairlyLongMethodName(
+ [relatively_long_identifier_for_a_list],
+ another_argument_with_a_long_identifier)
+ """)
+ uwlines = _ParseAndUnwrap(code)
+ self.assertCodeEqual(code, reformatter.Reformat(uwlines))
+
def testB25136820(self):
unformatted_code = textwrap.dedent("""\
def foo():