Currently, callable classes will not be picked up by doit
, though it can be nice way to define many tasks. Minimal example:
class Adder(object):
def __init__(self, a):
self.a = a
def add(self, b):
return self.a + b
def __call__(self, b):
return {'actions': [(self.add, [b])]}
task_add3 = Adder(3)
task_add5 = Adder(5)
Currently I am using the following workaround, which works, but is a little messy.
task_add3 = lambda: Adder(3)()
task_add5 = lambda: Adder(5)()
I haven't looked at the code, but I am guessing that somewhere, the locals or globals are inspected, and elements that match the name regex and are functions are executed by doit. It should be sufficient to just change this logic to test if the item is callable, rather than being a function (as functions are callable).
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too