pylint icon indicating copy to clipboard operation
pylint copied to clipboard

useless-super-delegation with ABC

Open rickwierenga opened this issue 3 years ago • 2 comments

Bug description

Subclassing an ABC and just calling parent raises useless-super-delegation.

Example:

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

from abc import ABC, abstractmethod


class MyABC(ABC):
    @abstractmethod
    def do_something(self):
        print("Some implementation!")


class MyConcrete(MyABC):
    def do_something(self):
        super().do_something()

Configuration

No response

Command used

pylint a.py

Pylint output

************* Module a
a.py:1:0: C0114: Missing module docstring (missing-module-docstring)
a.py:9:2: W0235: Useless super delegation in method 'do_something' (useless-super-delegation)

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

Expected behavior

I guess you'd not want to raise the useless-super-delegation since this delegation is not useless.

Pylint version

pylint 2.14.3
astroid 2.11.6
Python 3.9.13 (main, May 24 2022, 21:13:51) 
[Clang 13.1.6 (clang-1316.0.21.2)]

OS / Environment

macOS 12.3.1

Additional dependencies

No response

rickwierenga avatar Sep 07 '22 20:09 rickwierenga

Why are you decorating the function as abstract in this example if you're using it later ? I think an abstract function should not have any behavior implemented, this is probably why we have a message that feel wrong here.

Pierre-Sassoulas avatar Sep 08 '22 08:09 Pierre-Sassoulas

I see how this could be a false positive. From PEP3119:

Unlike Java’s abstract methods or C++’s pure abstract methods, abstract methods as defined here may have an implementation. This implementation can be called via the super mechanism from the class that overrides it. This could be useful as an end-point for a super-call in framework using cooperative multiple-inheritance

mbyrnepr2 avatar Sep 08 '22 21:09 mbyrnepr2