Repository: asottile/pyupgrade

Issue:
`set` with trailing comma after list causes syntax error
```python
set(
    [
        1, 2, 3,
    ],
)
```

currently gets rewritten to (`SyntaxError`)

```python
{
        1, 2, 3,
    ,
}
```

Discussion:

Patch:
diff --git a/pyupgrade.py b/pyupgrade.py
index c7a8d26..2f8626c 100644
--- a/pyupgrade.py
+++ b/pyupgrade.py
@@ -233,6 +233,8 @@ def _victims(tokens, start, arg, gen):
                 ends.extend((i - 1, i))
             else:
                 ends.append(i)
+            if len(brace_stack) > 1 and tokens[i + 1].src == ',':
+                ends.append(i + 1)
 
         if is_end_brace:
             brace_stack.pop()
@@ -245,9 +247,9 @@ def _victims(tokens, start, arg, gen):
         while tokens[i].name in NON_CODING_TOKENS:
             i -= 1
         if tokens[i].src == ',':
-            ends = sorted(set(ends + [i]))
+            ends.append(i)
 
-    return Victims(starts, ends, first_comma_index, arg_index)
+    return Victims(starts, sorted(set(ends)), first_comma_index, arg_index)
 
 
 def _find_token(tokens, i, token):  # type: (List[Token], int, Token) -> int


Test patch:
diff --git a/tests/set_literals_test.py b/tests/set_literals_test.py
index 22ac4d6..50363be 100644
--- a/tests/set_literals_test.py
+++ b/tests/set_literals_test.py
@@ -85,6 +85,16 @@ def test_fix_sets_noop(s):
             '    x for x in y\n'
             '}',
         ),
+        (
+            'set(\n'
+            '    [\n'
+            '        99, 100,\n'
+            '    ],\n'
+            ')\n',
+            '{\n'
+            '        99, 100,\n'
+            '}\n',
+        ),
     ),
 )
 def test_sets(s, expected):