Task subclassing - docs example incorrect #495

bretth opened this Issue Dec 11, 2011 · 5 comments


None yet

3 participants

bretth commented Dec 11, 2011

[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

   class CustomTask(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')
    def actual_task():

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.:

class CustomTask(Task):
    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 :)

@bitprophet bitprophet closed this Dec 12, 2011
bretth commented Dec 12, 2011

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


@bitprophet bitprophet reopened this Dec 12, 2011
@bitprophet bitprophet was assigned Dec 12, 2011

Yea, I see that now, thanks :) Reopening.

@markatto markatto added a commit to markatto/fabric that referenced this issue Jan 17, 2012
@markatto markatto Updated the documentation for task subclassing. Fixes #495. 81aec53

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.

@bitprophet bitprophet added a commit that referenced this issue Feb 14, 2012
@bitprophet bitprophet Changelog re #495 8612588
@bitprophet bitprophet closed this Feb 14, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment