diff --git a/CHANGELOG b/CHANGELOG index ed71b5794..a76f7d065 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ - Treat expansion operators ('*', '**') in a similar way to function calls to avoid splitting directly after the opening parenthesis. - Increase the penalty for splitting after the start of a tuple. +- Increase penalty for excess characters. ## [0.16.1] 2017-03-22 ### Changed diff --git a/yapf/yapflib/style.py b/yapf/yapflib/style.py index 0d4ee04f1..a84f2bce7 100644 --- a/yapf/yapflib/style.py +++ b/yapf/yapflib/style.py @@ -228,7 +228,7 @@ def CreatePEP8Style(): SPLIT_PENALTY_AFTER_UNARY_OPERATOR=10000, SPLIT_PENALTY_BEFORE_IF_EXPR=0, SPLIT_PENALTY_BITWISE_OPERATOR=300, - SPLIT_PENALTY_EXCESS_CHARACTER=3500, + SPLIT_PENALTY_EXCESS_CHARACTER=4500, SPLIT_PENALTY_FOR_ADDED_LINE_SPLIT=30, SPLIT_PENALTY_IMPORT_NAMES=0, SPLIT_PENALTY_LOGICAL_OPERATOR=300, diff --git a/yapftests/reformatter_basic_test.py b/yapftests/reformatter_basic_test.py index 36c03e9e5..569f46581 100644 --- a/yapftests/reformatter_basic_test.py +++ b/yapftests/reformatter_basic_test.py @@ -1163,6 +1163,24 @@ def bar(self): uwlines = yapf_test_helper.ParseAndUnwrap(code) self.assertCodeEqual(code, reformatter.Reformat(uwlines)) + unformatted_code = textwrap.dedent("""\ + def _(): + if True: + if True: + if contract == allow_contract and attr_dict.get(if_attribute) == has_value: + return True + """) + expected_code = textwrap.dedent("""\ + def _(): + if True: + if True: + if contract == allow_contract and attr_dict.get( + if_attribute) == has_value: + return True + """) + uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code) + self.assertEqual(expected_code, reformatter.Reformat(uwlines)) + def testDictSetGenerator(self): code = textwrap.dedent("""\ foo = {