I’m trying to create a Python class (let’s say ETL
) which obtains it’s behaviour from a number of base classes (Extractor
, Transformer
, Loader
). However, for one of these base classes the behaviour should be determined based on the parameters passed during the intialization of ETL
.
I have tried adding the specific transformer class to self.__class__bases__
in Transformer.__init__
but that seems to create all kinds of issues including TypeError: Cannot create a consistent method resolution order (MRO)
.
How can I best architect this?
class Extractor:
def extract(self):
pass
class FooTransformer:
def transform(self):
pass
class BarTransformer:
def transform(self):
pass
class Transformer:
def __init__(self):
# dynamically decide which transformer to inherit based on self.transformation?
pass
class Loader:
def load(self):
pass
class ETL(Extractor, Transformer, Loader):
def __init__(self, transformation):
self.transformation = transformation
def run(self):
self.extract()
self.transform()
self.load()
etl = ETL()
etl.run()