Abstract methods and inheritance

In the following example:

class Grandpa:
    def m(self):

class Papa(Grandpa):
    def m(self):

class Son(Papa):

PyCharm says: Class Son must implement all abstract methods. But it was implemented in Papa. The warning goes away if I do:

class Son(Papa):
    def m(self):
        return super().m()

But it doesn't seem 'pythonic' (or even reasonable) to write redundant code.

Am I doing something wrong? Or is it a bug in the inspection?

Thank you.
1 comment

I believe that it is just a "bug" in the inspection of PyCharm. Seems to me, that it doesn't look into multiple level inheritances. Just checks if the the class Son is of type Grandpa (which is, through inheritance of Papa) and then checks if the method is implemented in Son...

There is nothing wrong with your code and it is perfectly pythonic.

For example online python tool at repl.it doesn't show the warning.

When you remove the method m from Papa then it correctly shows warning for Son and Papa as it's not implemented in any of them.

EDIT: This was already fixed and is not present in current PyCharm versions (2017+)


Please sign in to leave a comment.