pylint icon indicating copy to clipboard operation
pylint copied to clipboard

useless-parent-delegation false positive when __init__ signatures differ but parent is built-in type

Open cemysce opened this issue 1 year ago • 0 comments

Bug description

# pylint: disable=missing-module-docstring,missing-class-docstring,too-few-public-methods

class CustomBuiltInType(list):
    def __init__(self):
        super().__init__()
    # pylint warns about this override:
    #   W0246: Useless parent or super() delegation in method '__init__' (useless-parent-delegation)
    # but the signature of this `__init__` is different from that of the parent class.
    # In other examples below, it recognizes the signature is different, and doesn't warn.
    # pylint doesn't seem to correctly handle the parent class being a built-in type.
    # I also tried `dict` as the parent, same issue.

class MyParentClass:
    def __init__(self, x=None):
        self.x = x

class ChildNoArg(MyParentClass):
    def __init__(self):
        super().__init__()

class ChildDefaultArg(MyParentClass):
    def __init__(self, x=None):
        if x:
            super().__init__(x)
        else:
            super().__init__()

class ChildYesArg(MyParentClass):
    def __init__(self, x):
        super().__init__(x)

Configuration

No response

Command used

pylint --persistent=n a.py

Pylint output

************* Module a
a.py:4:4: W0246: Useless parent or super() delegation in method '__init__' (useless-parent-delegation)

-----------------------------------
Your code has been rated at 9.41/10

Expected behavior

This should not be considered a useless-parent-delegation because the signatures of the two __init__ methods are different -- the parent class (either list or dict) takes optional arguments, whereas the child class CustomBuiltInType takes no arguments. That's how it works normally (see other examples in code).

Pylint version

pylint 3.0.3
astroid 3.0.2
Python 3.11.5 (main, Sep  5 2023, 20:36:50) [GCC 12.3.1 20230526]

OS / Environment

Gentoo Linux, with profile default/linux/amd64/17.1/desktop/plasma. However I ran this inside a venv, in which I only installed pylint.

Additional dependencies

No response

cemysce avatar Jan 12 '24 07:01 cemysce