Skip to content

Commit

Permalink
don't rewrite old super calls for __new__
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Sep 25, 2021
1 parent dd1fe7f commit 1a76829
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyupgrade/_plugins/legacy.py
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/features/super_test.py
Expand Up @@ -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):
Expand Down

0 comments on commit 1a76829

Please sign in to comment.