From 46f6f773b3c36194a96fd0889ed5ad6ae0059aed Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 30 Dec 2021 08:35:35 -0800 Subject: [PATCH] don't rewrite six.reraise with named args --- pyupgrade/_plugins/six_calls.py | 13 +++++++++++-- tests/features/six_test.py | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pyupgrade/_plugins/six_calls.py b/pyupgrade/_plugins/six_calls.py index 90c4ee30..ac58fd57 100644 --- a/pyupgrade/_plugins/six_calls.py +++ b/pyupgrade/_plugins/six_calls.py @@ -172,13 +172,21 @@ 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, @@ -186,6 +194,7 @@ def visit_Call( 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( diff --git a/tests/features/six_test.py b/tests/features/six_test.py index e1f6cd88..4ea3f5b5 100644 --- a/tests/features/six_test.py +++ b/tests/features/six_test.py @@ -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',