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

Register pre-defined hook with arguments #35

Open
timlehr opened this issue Jun 22, 2018 · 1 comment
Open

Register pre-defined hook with arguments #35

timlehr opened this issue Jun 22, 2018 · 1 comment

Comments

@timlehr
Copy link

timlehr commented Jun 22, 2018

Hi Rotem,

Thanks for developing Gossip. I love it!
I'm currently using it as part of a framework I'm writing, so I'm pre-defining a lot of hooks I use in different places. I always store the hook object and use it directly for registration (to have the hook name defined in only one place), but I'm hitting a wall when using arguments with these objects. I'm using strict groups.

# Works fine
myhook = gossip.define("mygroup.testhook", arg_names=["some_arg"])

@myhook.register
def some_function(some_arg):
    pass
# Does not work: 
myhook = gossip.define("mygroup.testhook", arg_names=["some_arg"], tags=["test"])

@myhook.register(tags=["test"])
def some_function(some_arg):
    pass

I always end up with the following
TypeError: register() takes at least 2 arguments (2 given)

Do I need to wrap the register() call to get the functionality I want?

Cheers!
Tim

@vmalloc
Copy link
Member

vmalloc commented Jun 22, 2018

Hi there!

First, glad to know that you like it! Thanks for the kind words.

Regarding your question -- the register method on hook objects is stricter than the global register, and this means it's not as convenient to be used as a decorator.

I'm open to a PR making it more convenient though - there's no objective reason why your example shouldn't be allowed.

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

No branches or pull requests

2 participants