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

Variable number of args and kwargs for handler functions #52

Closed
michaelimfeld opened this issue Oct 18, 2016 · 2 comments
Closed

Variable number of args and kwargs for handler functions #52

michaelimfeld opened this issue Oct 18, 2016 · 2 comments
Assignees
Labels

Comments

@michaelimfeld
Copy link

Hi

I couldn't find anything about this in the docs:
Does this library support a variable number of args and kwargs for a handler function?

Example:

@dispatcher.add_method
def foobar(*args, **kwargs):
    return kwargs["foo"] + kwargs["bar"] + args[0]
@pavlov99
Copy link
Owner

@michaelimfeld it does support a variable number of arguments, however, with slightly different approach. JSON-RPC standard allows arguments of the function to be sent either as list or dictionary, but not as a mix of them. This library follows the standard and does not allow both *args and **kwargs at the same time. There is a workaround in your case, args could be extra key of kwargs:

@dispatcher.add_method
def foobar(**kwargs):
    return kwargs["foo"] + kwargs["bar"] + kwargs["args"][0]

Payload in this case would have params value:

{"foo": 1, "bar": 2, "args": [3]}

Does it work?

@pavlov99 pavlov99 self-assigned this Oct 18, 2016
@michaelimfeld
Copy link
Author

Yes, works!

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

No branches or pull requests

2 participants