aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Wendling <morbo@google.com>2018-03-27 15:31:54 -0700
committerBill Wendling <morbo@google.com>2018-03-27 15:31:54 -0700
commit4ddb2fe57039fd0b5eea561c89c9b6574d7e7216 (patch)
tree0c2a2f60d42f4b948d5500d446b8594da65c36b1
parent8f8c5f51fb7da87aedcc8b2f4fca0d66dd554394 (diff)
downloadyapf-4ddb2fe57039fd0b5eea561c89c9b6574d7e7216.tar.gz
Increase the affinity of the closing paren to arg list
-rw-r--r--CHANGELOG1
-rw-r--r--yapf/yapflib/split_penalty.py4
-rw-r--r--yapftests/reformatter_buganizer_test.py46
3 files changed, 51 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 904d01a..7dc793c 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -14,6 +14,7 @@
analyzed. This allows tuples to be split more rationally.
- Adjust splitting penalties around arithmetic operators so that the code can
flow more freely. The code must flow!
+- Try to meld an argument list's closing parenthesis to the last argument.
### Fixed
- Attempt to determine if long lambdas are allowed. This can be done on a
case-by-case basis with a "pylint" disable comment.
diff --git a/yapf/yapflib/split_penalty.py b/yapf/yapflib/split_penalty.py
index f815804..fe32e49 100644
--- a/yapf/yapflib/split_penalty.py
+++ b/yapf/yapflib/split_penalty.py
@@ -231,6 +231,10 @@ class _SplitPenaltyAssigner(pytree_visitor.PyTreeVisitor):
}:
# Don't split an argument list with one element if at all possible.
_SetStronglyConnected(node.children[1], node.children[2])
+
+ if name == 'arglist':
+ _SetStronglyConnected(node.children[-1])
+
self.DefaultNodeVisit(node)
def Visit_power(self, node): # pylint: disable=invalid-name,missing-docstring
diff --git a/yapftests/reformatter_buganizer_test.py b/yapftests/reformatter_buganizer_test.py
index 8f6ebac..ffb6ded 100644
--- a/yapftests/reformatter_buganizer_test.py
+++ b/yapftests/reformatter_buganizer_test.py
@@ -28,6 +28,52 @@ class BuganizerFixes(yapf_test_helper.YAPFTest):
def setUpClass(cls):
style.SetGlobalStyle(style.CreateChromiumStyle())
+ def testB65546221(self):
+ unformatted_code = """\
+class _():
+
+ def _():
+ return timedelta(seconds=max(float(time_scale), small_interval) *
+ 1.41 ** min(num_attempts, 9))
+"""
+ expected_formatted_code = """\
+class _():
+
+ def _():
+ return timedelta(
+ seconds=max(float(time_scale), small_interval) *
+ 1.41**min(num_attempts, 9))
+"""
+ uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
+ self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(uwlines))
+
+ def testB65546221(self):
+ unformatted_code = """\
+SUPPORTED_PLATFORMS = (
+ "centos-6",
+ "centos-7",
+ "ubuntu-1204-precise",
+ "ubuntu-1404-trusty",
+ "ubuntu-1604-xenial",
+ "debian-7-wheezy",
+ "debian-8-jessie",
+ "debian-9-stretch",)
+"""
+ expected_formatted_code = """\
+SUPPORTED_PLATFORMS = (
+ "centos-6",
+ "centos-7",
+ "ubuntu-1204-precise",
+ "ubuntu-1404-trusty",
+ "ubuntu-1604-xenial",
+ "debian-7-wheezy",
+ "debian-8-jessie",
+ "debian-9-stretch",
+)
+"""
+ uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
+ self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(uwlines))
+
def testB30500455(self):
unformatted_code = """\
INITIAL_SYMTAB = dict([(name, 'exception#' + name) for name in INITIAL_EXCEPTIONS