Skip to content
Advertisement

AttributeError: ‘NoneType’ object has no attribute ‘sink’ [closed]

I need to develop a demo ETL system that need to run from following fluent python format

ETL().source(source_args).sink(sink_args).run()

I made the class ETL() after this I made a function source and function sink in the class. Code looks like this:

class ETL:

    def source(self, data_source: str):
        if data_source == 'Simulation':
            simulation()
        elif data_source == 'File':
            main()

    def sink(self, data_sink: str):
        if data_sink == 'Console':
            command = 'Continue'
            user_command = input('Please type to Continue or to Stop!')
            while command != 'Stop':
                simulation()

        else:
            pass

ETL().source('Simulation').sink('Console')

When I run the file I receive this error:

AttributeError: ‘NoneType’ object has no attribute ‘sink’

Where I am wrong and how to add the last method .run()? I take simulation() function from another file but this is not the problem.

Advertisement

Answer

You’ve found the answer anyway, but I’ll just add some return self to your code:

class ETL:

    def source(self, data_source: str):
        if data_source == 'Simulation':
            simulation()
        elif data_source == 'File':
            main()
        return self

    def sink(self, data_sink: str):
        if data_sink == 'Console':
            command = 'Continue'
            user_command = input('Please type to Continue or to Stop!')
            while command != 'Stop':
                simulation()
        return self

ETL().source('Simulation').sink('Console')

The above code will now work without the error.

However, you also ask about the run() method. I want to know what that is supposed to do. To me it looks like the sink() method, having a while loop is doing the run thing.

Perhaps you meant to do this:

# code elided ...
    def sink(self, data_sink: str):
        self.data_sink = data_sink
        return self

    def run(self):
        if self.data_sink == 'Console':
            command = 'Continue'
            user_command = input('Please type to Continue or to Stop!')
            while command != 'Stop':
                simulation()

# Now this will work:
ETL().source(source_args).sink(sink_args).run()
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement