dario
dario

Reputation: 145

Inherited Abstract Classes in python

In python, can I define an interface (abstract class) by inheritance from another abstract class? If I try:

import abc
ABC = abc.ABCMeta('ABC', (object,), {})

class interface(ABC):
    @abc.abstractmethod
    def method(self, message):
        return


class InterfaceExtended(ABC, interface):
    @abc.abstractmethod
    def NewMethod(self, message):
        return

I get an error on the "InterfaceExtended" class :

TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases ABC, Interface

Upvotes: 3

Views: 2544

Answers (1)

Angus Hollands
Angus Hollands

Reputation: 396

Don't inherit from ABC in your second class. The interface it derives from already inherits ABC

Upvotes: 2

Related Questions