aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Wendling <morbo@google.com>2018-03-30 20:45:14 -0700
committerBill Wendling <morbo@google.com>2018-03-30 21:02:31 -0700
commitd059cc4fcf3156f6f7ac3b3408ed86535751500e (patch)
tree98eb2c035ff9da8bff6c423243ddf0c40efb2ae0
parent7cfb6b10b65e6db1f09583e5cc6a5f5bb7937f4f (diff)
downloadyapf-d059cc4fcf3156f6f7ac3b3408ed86535751500e.tar.gz
Start new wrapped line only if comment is first item in decorator node
-rw-r--r--CHANGELOG2
-rw-r--r--yapf/yapflib/blank_line_calculator.py2
-rw-r--r--yapf/yapflib/identify_container.py2
-rw-r--r--yapf/yapflib/pytree_unwrapper.py3
-rw-r--r--yapftests/reformatter_buganizer_test.py20
5 files changed, 23 insertions, 6 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 7dc793c..6970b8d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -19,6 +19,8 @@
- Attempt to determine if long lambdas are allowed. This can be done on a
case-by-case basis with a "pylint" disable comment.
- A comment before a decorator isn't part of the decorator's line.
+- Only force a new wrapped line after a comment in a decorator when it's the
+ first token in the decorator.
## [0.21.0] 2018-03-18
### Added
diff --git a/yapf/yapflib/blank_line_calculator.py b/yapf/yapflib/blank_line_calculator.py
index 0a4fcc2..c239ee7 100644
--- a/yapf/yapflib/blank_line_calculator.py
+++ b/yapf/yapflib/blank_line_calculator.py
@@ -22,8 +22,6 @@ Annotations:
newlines: The number of newlines required before the node.
"""
-from lib2to3 import pytree
-
from yapf.yapflib import py3compat
from yapf.yapflib import pytree_utils
from yapf.yapflib import pytree_visitor
diff --git a/yapf/yapflib/identify_container.py b/yapf/yapflib/identify_container.py
index 23630c5..5c5fc5b 100644
--- a/yapf/yapflib/identify_container.py
+++ b/yapf/yapflib/identify_container.py
@@ -19,8 +19,6 @@ to the opening bracket and vice-versa.
IdentifyContainers(): the main function exported by this module.
"""
-from lib2to3 import pytree
-
from yapf.yapflib import pytree_utils
from yapf.yapflib import pytree_visitor
diff --git a/yapf/yapflib/pytree_unwrapper.py b/yapf/yapflib/pytree_unwrapper.py
index 049dbbb..550bc89 100644
--- a/yapf/yapflib/pytree_unwrapper.py
+++ b/yapf/yapflib/pytree_unwrapper.py
@@ -225,7 +225,8 @@ class PyTreeUnwrapper(pytree_visitor.PyTreeVisitor):
def Visit_decorator(self, node): # pylint: disable=invalid-name
for child in node.children:
self.Visit(child)
- if pytree_utils.NodeName(child) == 'COMMENT':
+ if (pytree_utils.NodeName(child) == 'COMMENT' and
+ child == node.children[0]):
self._StartNewLine()
def Visit_decorators(self, node): # pylint: disable=invalid-name
diff --git a/yapftests/reformatter_buganizer_test.py b/yapftests/reformatter_buganizer_test.py
index ffb6ded..519b0f1 100644
--- a/yapftests/reformatter_buganizer_test.py
+++ b/yapftests/reformatter_buganizer_test.py
@@ -28,7 +28,25 @@ class BuganizerFixes(yapf_test_helper.YAPFTest):
def setUpClass(cls):
style.SetGlobalStyle(style.CreateChromiumStyle())
- def testB65546221(self):
+ def testB77329955(self):
+ code = """\
+class _():
+
+ @parameterized.named_parameters(
+ ('ReadyExpiredSuccess', True, True, True, None, None),
+ ('SpannerUpdateFails', True, False, True, None, None),
+ ('ReadyNotExpired', False, True, True, True, None),
+ # ('ReadyNotExpiredNotHealthy', False, True, True, False, True),
+ # ('ReadyNotExpiredNotHealthyErrorFails', False, True, True, False, False
+ # ('ReadyNotExpiredNotHealthyUpdateFails', False, False, True, False, True
+ )
+ def _():
+ pass
+"""
+ uwlines = yapf_test_helper.ParseAndUnwrap(code)
+ self.assertCodeEqual(code, reformatter.Reformat(uwlines))
+
+ def testB65197969(self):
unformatted_code = """\
class _():