Skip to content

Conversation

@Mahi
Copy link
Contributor

@Mahi Mahi commented Dec 5, 2015

Before if you did this:

@ClientCommand('test')
@SayCommand('test')
def test(*args):
    print('test() was called')

It would raise an error because _BaseCommand.__call__() returns the command instance itself, as opposed to the original test function. This would cause SayCommand to attempt to register the ClientCommand instance as a callback, which would fail.

@Ayuto already hotfixed this here, but I believe that's just a workaround and doesn't solve the actual issue: the decorator is returned instead of the decorated function. Also, his workaround still doesn't allow one to call the test() function after decorating it as a command. The following code wouldn't work because test is now a ClientCommand instance:

@ClientCommand('test')
def test(*args):
    print('test() was called')

test()

Returning the command instance was necessary with the old AutoUnload class which operated on global variables based on their name, but this update greatly improved the mechanism and returning the object is no longer required.

@Mahi Mahi changed the title Allow chaining of multiple commands _BaseCommand's __call__ returns the original callback Dec 5, 2015
@Mahi Mahi changed the title _BaseCommand's __call__ returns the original callback Commands' __call__ returns the original callback Dec 5, 2015
@Mahi Mahi changed the title Commands' __call__ returns the original callback Return the original callback from commands' __call__ Dec 5, 2015
@satoon101
Copy link
Member

This looks correct, but I would like to test it when I get home tonight before pulling. Thank you!

@Ayuto
Copy link
Member

Ayuto commented Dec 5, 2015

The same actually applies to all other decorators (e.g. the Event decorator).

@Mahi
Copy link
Contributor Author

Mahi commented Dec 5, 2015

Yeah good point, I didn't have too much time to go through all the decorators.

satoon101 added a commit that referenced this pull request Dec 6, 2015
Return the original callback from commands' __call__
@satoon101 satoon101 merged commit 503b2cc into Source-Python-Dev-Team:master Dec 6, 2015
@satoon101
Copy link
Member

Thanks again. I will update the other decorators as needed today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants