diff --git a/pyupgrade/_plugins/legacy.py b/pyupgrade/_plugins/legacy.py index 8de3fa75..f7ba3763 100644 --- a/pyupgrade/_plugins/legacy.py +++ b/pyupgrade/_plugins/legacy.py @@ -126,6 +126,7 @@ def visit_Call(self, node: ast.Call) -> None: # argument of this function isinstance(self._scopes[-1].node, NON_LAMBDA_FUNC_TYPES) and node.func.attr == self._scopes[-1].node.name and + node.func.attr != '__new__' and len(self._scopes[-1].node.args.args) >= 1 and node.args[0].id == self._scopes[-1].node.args.args[0].arg and # the function is an attribute of the contained class name diff --git a/tests/features/super_test.py b/tests/features/super_test.py index 124f87df..8e3be14f 100644 --- a/tests/features/super_test.py +++ b/tests/features/super_test.py @@ -182,6 +182,12 @@ def test_fix_super(s, expected): ' def find(self):\n' ' return C.make(self)\n', ), + pytest.param( + 'class C(tuple):\n' + ' def __new__(cls, arg):\n' + ' return tuple.__new__(cls, (arg,))\n', + id='super() does not work properly for __new__', + ), ), ) def test_old_style_class_super_noop(s):