Skip to content

Commit

Permalink
don't rewrite six.reraise with named args
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Dec 30, 2021
1 parent 234e071 commit 46f6f77
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pyupgrade/_plugins/six_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,29 @@ def visit_Call(
('reraise',),
)
):
if len(node.args) == 2 and not has_starargs(node):
if (
len(node.args) == 2 and
not node.keywords and
not has_starargs(node)
):
func = functools.partial(
find_and_replace_call,
template=RERAISE_2_TMPL,
)
yield ast_to_offset(node), func
elif len(node.args) == 3 and not has_starargs(node):
elif (
len(node.args) == 3 and
not node.keywords and
not has_starargs(node)
):
func = functools.partial(
find_and_replace_call,
template=RERAISE_3_TMPL,
)
yield ast_to_offset(node), func
elif (
len(node.args) == 1 and
not node.keywords and
isinstance(node.args[0], ast.Starred) and
isinstance(node.args[0].value, ast.Call) and
is_name_attr(
Expand Down
1 change: 1 addition & 0 deletions tests/features/six_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
'class C(six.with_metaclass(Meta, B), D): pass',
# cannot determine args to rewrite them
'six.reraise(*err)', 'six.u(*a)',
'six.reraise(a, b, tb=c)',
'class C(six.with_metaclass(*a)): pass',
'@six.add_metaclass(*a)\n'
'class C: pass\n',
Expand Down

0 comments on commit 46f6f77

Please sign in to comment.