Skip to content

False positive unnecessary-dunder-call when overriding dunder method #6074

@jacobtylerwalls

Description

@jacobtylerwalls

Bug description

class A(list):
    def __contains__(self, item):
        print("do some special checks")
        return super().__contains__(item)  # raises unnecessary-dunder-call

Configuration

No response

Command used

pylint a.py

Pylint output

************* Module a
a.py:4: [C2801(unnecessary-dunder-call), A.__contains__] Unnecessarily calls dunder method __contains__. Use in keyword.

Expected behavior

No message, since the example cannot be rewritten as return item in super():

TypeError: argument of type 'super' is not iterable

This wasn't happening for __init__ because it was allow-listed, but I think all dunder methods could be overridden in subclasses, so they all need to be made compatible with super().__...

Pylint version

pylint 2.14.0-dev0
astroid 2.12.0-dev0
Python 3.10.2 (v3.10.2:a58ebcc701, Jan 13 2022, 14:50:16) [Clang 13.0.0 (clang-1300.0.29.30)]

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    False Positive 🦟A message is emitted but nothing is wrong with the code

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions