[EDITOR'S NOTE: the problem is actually with the Task docs' example code, which is out of date and should reflect my comment below re: __init__.]
In the documentation for tasks "Using custom subclasses with @task", raises an error:
TypeError: init() got an unexpected keyword argument 'alias'.
from fabric.api import task
from fabric.tasks import Task
def __init__(self, func, myarg):
self.func = func
self.myarg = myarg
def run(self, *args, **kwargs):
return self.func(*args, **kwargs)
@task(task_class=CustomTask, myarg='value', alias='at')
That's because you're redefining your subclass' __init__ and aren't giving it an alias keyword argument. Check out how the real Task class is implemented to see how it can/should be extended. Typically, it's best to override superclass' __init__ methods in a wide-open fashion so you never have to worry about "copying" the superclass' specific argument structure, i.e.:
def __init__(self, *args, **kwargs):
super(CustomTask, self).__init__(*args, **kwargs)
self.myarg = kwargs['myarg']
If you need more help with this, please see a general Python resource, Fabric isn't doing anything terrifically special here :)
Ok yes it caught me out but it's a mistake in the docs http://docs.fabfile.org/en/1.3.3/usage/tasks.html
Yea, I see that now, thanks :) Reopening.
Updated the documentation for task subclassing. Fixes #495.
I have attempted to correct the documentation: markatto@81aec53
@markatto -- if you reload this page you'll see this, but simply referencing "#N" in the commit message is enough to get a note added here. No need for a manual note/link anymore! :)
Thanks for taking a stab, I will try to review for the next bugfix release.
Changelog re #495