Can Protocol Child Classes Contain Extra Methods In Python?

176 views Asked by At

I have a situation where we have taken data from a singular source and stored it in a database. I am hoping to implement a protocol in python so that I can add other data sources and have my program follow a similar flow. In both cases I will be extracting data, transforming it, then loading it so that's the structure I want for the protocol, but any of those stages could have provider-specific logic to them.

My question is, would the below minimum example be implementing the Transferrer protocol, or do the additional methods in the child class exclude them from the protocol?

class Transferrer(Protocol):
    def extract_data(self):
        raise NotImplementedError()
    def transform_data(self):
        raise NotImplementedError()
    def load_data(self):
        raise NotImplementedError()

class Provider_1_Transferrer:
    def provider_1_specific_cleaning_subprocess(self):
        ...
    def extract_data(self):
        ...
    def transform_data(self):
        self.provider_1_specific_cleaning_subprocess()
    def load_data(self):
        ...

class Provider_2_Transferrer:
    def provider_2_specific_cleaning_subprocess(self):
        ...
    def extract_data(self):
        ...
    def transform_data(self):
        self.provider_2_specific_cleaning_subprocess()
    def load_data(self):
        ...

I am just getting into using protocols, so I apologise if this is quite basic or has been answered elsewhere.

0

There are 0 answers