A comment before a decorator isn't part of the decorator.
diff --git a/CHANGELOG b/CHANGELOG
index 0a00c8c..699428b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -15,6 +15,7 @@
### Fixed
- 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.
## [0.21.0] 2018-03-18
### Added
diff --git a/yapf/yapflib/pytree_unwrapper.py b/yapf/yapflib/pytree_unwrapper.py
index f6be260..bbb5cdb 100644
--- a/yapf/yapflib/pytree_unwrapper.py
+++ b/yapf/yapflib/pytree_unwrapper.py
@@ -222,6 +222,12 @@
for child in node.children[index].children:
self.Visit(child)
+ def Visit_decorator(self, node): # pylint: disable=invalid-name
+ for child in node.children:
+ self.Visit(child)
+ if pytree_utils.NodeName(child) == 'COMMENT':
+ self._StartNewLine()
+
def Visit_decorators(self, node): # pylint: disable=invalid-name
for child in node.children:
self._StartNewLine()
diff --git a/yapftests/reformatter_buganizer_test.py b/yapftests/reformatter_buganizer_test.py
index 5b50c28..914befc 100644
--- a/yapftests/reformatter_buganizer_test.py
+++ b/yapftests/reformatter_buganizer_test.py
@@ -28,6 +28,18 @@
def setUpClass(cls):
style.SetGlobalStyle(style.CreateChromiumStyle())
+ def testB38343525(self):
+ code = """\
+# This does foo.
[email protected]('some_path_to_a_file', required=True)
+# This does bar.
[email protected]('some_path_to_a_file', required=True)
+def f():
+ print 1
+"""
+ uwlines = yapf_test_helper.ParseAndUnwrap(code)
+ self.assertCodeEqual(code, reformatter.Reformat(uwlines))
+
def testB37099651(self):
unformatted_code = """\
_MEMCACHE = lazy.MakeLazy(