Repository: asottile/pyupgrade

Issue:
`add_metaclass` rewrite indentation is strange when indented
Currently:

```diff
 if True:
-    @six.add_metaclass(M)
-    class C: pass
+        class C(metaclass=M): pass
```

Discussion:

Patch:
diff --git a/pyupgrade.py b/pyupgrade.py
index 8d11da1..ac8bd70 100644
--- a/pyupgrade.py
+++ b/pyupgrade.py
@@ -1114,6 +1114,8 @@ class FindPy3Plus(ast.NodeVisitor):
 def _remove_decorator(tokens, i):
     while tokens[i - 1].src != '@':
         i -= 1
+    if i > 1 and tokens[i - 2].name not in {'NEWLINE', 'NL'}:
+        i -= 1
     end = i + 1
     while tokens[end].name != 'NEWLINE':
         end += 1


Test patch:
diff --git a/tests/pyupgrade_test.py b/tests/pyupgrade_test.py
index 7c76a51..87ac751 100644
--- a/tests/pyupgrade_test.py
+++ b/tests/pyupgrade_test.py
@@ -1387,6 +1387,16 @@ def test_fix_six_noop(s):
 
             id='add_metaclass, weird base that contains a :',
         ),
+        pytest.param(
+            'if True:\n'
+            '    @six.add_metaclass(M)\n'
+            '    class C: pass\n',
+
+            'if True:\n'
+            '    class C(metaclass=M): pass\n',
+
+            id='add_metaclass, indented',
+        ),
     ),
 )
 def test_fix_six(s, expected):