Skip to content

Commit

Permalink
Don't squish all the args to the RHS
Browse files Browse the repository at this point in the history
It looks bad when they're all aligned over to the right when there's all
this whitespace being wasted.
  • Loading branch information
bwendling committed Feb 17, 2017
1 parent 79b82ef commit bd245fb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
- Ensure splitting of arguments if there's a named assign present.
- Prefer to coalesce opening brackets if it's not at the beginning of a
function call.
- Prefer not to squish all of the elements in a function call over to the
right-hand side. Split the arguments instead.

## [0.16.0] 2017-02-05
### Added
Expand Down
4 changes: 4 additions & 0 deletions yapf/yapflib/format_decision_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ def MustSplit(self):
# line and it's not a function call.
if self._FitsOnLine(previous, previous.matching_bracket):
return False
elif not self._FitsOnLine(previous, previous.matching_bracket):
if (self.column_limit - self.column) / float(self.column_limit) < 0.3:
# Try not to squish all of the arguments off to the right.
return True
else:
# Split after the opening of a container if it doesn't fit on the
# current line or if it has a comment.
Expand Down
27 changes: 27 additions & 0 deletions yapftests/reformatter_basic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,33 @@ def method(self):
finally:
style.SetGlobalStyle(style.CreateChromiumStyle())

def testStableInlinedDictionaryFormatting(self):
try:
style.SetGlobalStyle(style.CreatePEP8Style())
unformatted_code = textwrap.dedent("""\
def _():
url = "http://{0}/axis-cgi/admin/param.cgi?{1}".format(
value, urllib.urlencode({'action': 'update', 'parameter': value}))
""")
expected_formatted_code = textwrap.dedent("""\
def _():
url = "http://{0}/axis-cgi/admin/param.cgi?{1}".format(
value, urllib.urlencode({
'action': 'update',
'parameter': value
}))
""")

uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
reformatted_code = reformatter.Reformat(uwlines)
self.assertCodeEqual(expected_formatted_code, reformatted_code)

uwlines = yapf_test_helper.ParseAndUnwrap(reformatted_code)
reformatted_code = reformatter.Reformat(uwlines)
self.assertCodeEqual(expected_formatted_code, reformatted_code)
finally:
style.SetGlobalStyle(style.CreateChromiumStyle())

def testDontSplitKeywordValueArguments(self):
unformatted_code = textwrap.dedent("""\
def mark_game_scored(gid):
Expand Down

0 comments on commit bd245fb

Please sign in to comment.