pythonluigi

In luigi what is the difference between the function requires and the @requires mark?


When specifying tasks some task comes like this

class aclass(luigi.Task):
    def requres(self):
        return [anotherTask]

others come like

@requires(anotherTask)
class aclass(luigi.Task):
    ....something

what is the difference and why should one use one over the other?


Solution

  • When defining def requires(self): you need to return a list of tasks instances, and pass them their parameters. If you have a lot of tasks that have the same parameters it means a lot of boiler plate.

    With decorator @requires you don't have to re-define the parameters, and you don't have to pass them, luigi does it for you.

    See https://luigi.readthedocs.io/en/stable/api/luigi.util.html