I am working on a codebase that I don't entirely master (yet). I have the following 3-class stucture:
class Processor(ABC):
@abstractmethod
def process(self, *args: Any, **kwargs: Any):
pass
class AbstractEsTask(Processor, ABC):
def calculate(self, param):
...
@DplTask
class EsDirectTask(AbstractEsTask):
def process(self):
return self.calculate(param = "DIRECT")
It seems to me that having AbstractEsTask
inherit from ABC
is superfluous, since Processor
already does.
I have tried editing the code accordingly (class AbstractEsTask(Processor, ABC)
-> class AbstractEsTask(Processor)
) and couldn't observe any change in the output. But, since it's a large codebase, this is probably not enough.
Is my understanding (in bold above) correct?
Your statement is correct because when
AbstractEsTask
inheritsProcessor
it will have access to all values ofABC
.Or in other words, if python can't find a method in
AbstractEsTask
, it will first look in Processor, and thenABC
. BecauseProcessor
has all of the elements thatABC
has,ABC
will never be needed. If a member is not found inProcessor
, it will not be found inABC
.I cannot think of any edge case where a double inheritance like you describe above would be necessary. Even if
Processor
modifies one of the methods ofABC
, the inheritance will not be affected becauseProcessor
is inherited first.This is described in the python docs