Repository: google/yapf

Issue:
Regression in formatting nested 'async def' functions
My style file has `blank_line_before_nested_class_or_def=False`.

Yapf 0.19.0 formats like:

```python
async def foo():
    async def bar():
        pass
```

Yapf 0.20.0 changes this to:

```python
async def foo():

    async def bar():
        pass
```

According to `git bisect`, this was introduced by 58e36945be8978deb7ab3ad3681f5feccb0405fc, which seems like it must be a bug, since that commit wasn't intended to change python 3 formatting at all.

Discussion:

Patch:
diff --git a/yapf/yapflib/reformatter.py b/yapf/yapflib/reformatter.py
index 7ed7a62..299fef8 100644
--- a/yapf/yapflib/reformatter.py
+++ b/yapf/yapflib/reformatter.py
@@ -439,7 +439,7 @@ def _IsClassOrDef(uwline):
   if uwline.first.value in {'class', 'def'}:
     return True
 
-  return (t.name for t in uwline.tokens[:2]) == ('async', 'def')
+  return [t.value for t in uwline.tokens[:2]] == ['async', 'def']
 
 
 def _CalculateNumberOfNewlines(first_token, indent_depth, prev_uwline,


Test patch:
diff --git a/yapftests/reformatter_python3_test.py b/yapftests/reformatter_python3_test.py
index c6a3e99..6ed1bbb 100644
--- a/yapftests/reformatter_python3_test.py
+++ b/yapftests/reformatter_python3_test.py
@@ -209,6 +209,17 @@ class TestsForPython3Code(yapf_test_helper.YAPFTest):
     uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
     self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(uwlines))
 
+  def testAsyncFunctionsNested(self):
+    if sys.version_info[1] < 5:
+      return
+    code = textwrap.dedent("""\
+        async def outer():
+            async def inner():
+                pass
+        """)
+    uwlines = yapf_test_helper.ParseAndUnwrap(code)
+    self.assertCodeEqual(code, reformatter.Reformat(uwlines))
+
   def testKeepTypesIntact(self):
     if sys.version_info[1] < 5:
       return