Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task subclassing - docs example incorrect #495

Closed
bretth opened this issue Dec 11, 2011 · 5 comments
Closed

Task subclassing - docs example incorrect #495

bretth opened this issue Dec 11, 2011 · 5 comments
Milestone

Comments

@bretth
Copy link

@bretth 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():
        pass
@bitprophet
Copy link
Member

@bitprophet bitprophet commented Dec 12, 2011

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

Loading

@bitprophet bitprophet closed this Dec 12, 2011
@bretth
Copy link
Author

@bretth 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
cheers,

Brett

Loading

@bitprophet bitprophet reopened this Dec 12, 2011
@ghost ghost assigned bitprophet Dec 12, 2011
@bitprophet
Copy link
Member

@bitprophet bitprophet commented Dec 12, 2011

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

Loading

markatto added a commit to markatto/fabric that referenced this issue Jan 17, 2012
@markatto
Copy link

@markatto markatto commented Jan 17, 2012

I have attempted to correct the documentation: markatto@81aec53

Loading

@bitprophet
Copy link
Member

@bitprophet bitprophet commented Jan 17, 2012

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

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants