Skip to content

Commit

Permalink
Merge pull request #476 from MarcoGorelli/pr/six_with_metaclass_multi…
Browse files Browse the repository at this point in the history
…line

fix six.with_metaclass and trailing commas
  • Loading branch information
asottile authored Jul 3, 2021
2 parents 5113675 + 7baa69b commit 3cd7014
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pyupgrade/_token_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,15 @@ def replace_call(
):
start_rest += 1

rest = tokens_to_src(tokens[start_rest:end - 1])
# Remove trailing comma
end_rest = end - 1
while (
tokens[end_rest - 1].name == 'OP' and
tokens[end_rest - 1].src == ','
):
end_rest -= 1

rest = tokens_to_src(tokens[start_rest:end_rest])
src = tmpl.format(args=arg_strs, rest=rest)
tokens[start:end] = [Token('CODE', src)]

Expand Down
7 changes: 7 additions & 0 deletions tests/features/six_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ def test_fix_six_noop(s):
id='elide object base in with_metaclass',
),
pytest.param(
'class C(six.with_metaclass(M, B,)): pass',
'class C(B, metaclass=M): pass',
id='with_metaclass and trailing comma',
),
pytest.param(
'@six.add_metaclass(M)\n'
'class C: pass\n',
Expand Down

0 comments on commit 3cd7014

Please sign in to comment.