Repository: asottile/pyupgrade

Issue:
Syntax errors created when removing with_metaclass
Code such as 
```
class EventProcessorMeta(six.with_metaclass(abc.ABCMeta)):
```

is being rewritten as invalid Python
```
class EventProcessorMeta(, metaclass=abc.ABCMeta):
``` 

Discussion:

Patch:
diff --git a/pyupgrade.py b/pyupgrade.py
index d3d7a55..6f2669b 100644
--- a/pyupgrade.py
+++ b/pyupgrade.py
@@ -914,7 +914,8 @@ SIX_CALLS = {
     'assertRegex': '{args[0]}.assertRegex({rest})',
 }
 SIX_B_TMPL = 'b{args[0]}'
-WITH_METACLASS_TMPL = '{rest}, metaclass={args[0]}'
+WITH_METACLASS_NO_BASES_TMPL = 'metaclass={args[0]}'
+WITH_METACLASS_BASES_TMPL = '{rest}, metaclass={args[0]}'
 SIX_RAISES = {
     'raise_from': 'raise {args[0]} from {rest}',
     'reraise': 'raise {args[1]}.with_traceback({args[2]})',
@@ -1221,7 +1222,11 @@ def _fix_py3_plus(contents_text):
         elif token.offset in visitor.six_with_metaclass:
             j = _find_open_paren(tokens, i)
             func_args, end = _parse_call_args(tokens, j)
-            _replace_call(tokens, i, end, func_args, WITH_METACLASS_TMPL)
+            if len(func_args) == 1:
+                tmpl = WITH_METACLASS_NO_BASES_TMPL
+            else:
+                tmpl = WITH_METACLASS_BASES_TMPL
+            _replace_call(tokens, i, end, func_args, tmpl)
         elif token.offset in visitor.super_calls:
             i = _find_open_paren(tokens, i)
             call = visitor.super_calls[token.offset]


Test patch:
diff --git a/tests/pyupgrade_test.py b/tests/pyupgrade_test.py
index 773ac80..b6988d7 100644
--- a/tests/pyupgrade_test.py
+++ b/tests/pyupgrade_test.py
@@ -1280,6 +1280,11 @@ def test_fix_six_noop(s):
             'from six import raise_from\nraise exc from exc_from',
             id='weird spacing raise_from',
         ),
+        (
+            'class C(six.with_metaclass(M)): pass',
+
+            'class C(metaclass=M): pass',
+        ),
         (
             'class C(six.with_metaclass(M, B)): pass',