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

Keyword arguments in reflection-based Caller/Callee #132

Open
supermihi opened this issue Mar 22, 2016 · 6 comments
Open

Keyword arguments in reflection-based Caller/Callee #132

supermihi opened this issue Mar 22, 2016 · 6 comments

Comments

@supermihi
Copy link

Hi,
is it possible to use keyword arguments (see WAMP specs with the simple, reflection-based API? It seems to be possible using the raw API, but that is rather cumbersome when implementing a lot of services.
Thanks,
Michael

@darkl
Copy link
Member

darkl commented Mar 22, 2016 via email

@supermihi
Copy link
Author

Hi Elad,
thans for your answer. Are there any plans to support kwargs for callers? I could think of an attribute to mark the keywords part, e.g.

[WampProcedure("com.example.keywordsexample")]
object KeywordsExample(int arg1, string arg2, [KwArgs] Dictionary<string, object> kwargs);

In my case, actually, there's a fixed set of keyword arguments (basically, some user identification) which I need to pass to all method calls. In order to avoid using the raw caller approach for all of these methods, I'm afraid I will have to implement a reflection-based caller mechanism based on a custom ProxyGenerator?

For the callee part: If I get it right, this means that e.g.

[WampProcedure("com.example.keywordsexample")]
object KeywordsExample(int arg1, string arg2, string user = null);

could be called with positional args [arg1=5, arg2="bar"] and kwargs {user="foo"}?

Michael

@darkl
Copy link
Member

darkl commented Mar 23, 2016

Hi,

I prefer having an attribute indicating whether the whole arguments are
positional or keywords. (Otherwise it might get too complicated)

Regarding callees: If you have a method

[WampProcedure("com.example.keywordsexample")]
object KeywordsExample(int arg1, string arg2, string user);

Then the arguments resolve is done in this order:

  • Check if you got 3 arguments in the arguments array
    • If yes, map every argument in the arguments array to the matching
      method argument (by the corresponding positional)
    • If not (you got n < 3 arguments) map the first n arguments to the n
      arguments of the method. Lookup the 3-n arguments from the kwArgs
      dictionary.

For example if you get args = [1,2,"Hello"], kwArgs = { "user": "Bill" },
then the method will be called with arg1=1,arg2=2,user="Hello".

If you get args = [1], kwArgs = { "arg2": 2, user: "Bill" }, then the
method will be called with arg1=1, arg2=2, user="Bill".
Elad

@supermihi
Copy link
Author

Hi Elad,
thanks, your examples made clear to me how it works. I'll think about the caller-side ... unfortunatelly, I'll need mixed positional and keyword argument because the service I want to use explicitly looks for the user id information in the kwargs part, where all other args ar explicitly positional.

@Chunky-Monkey
Copy link

Hi Elad,
a few years have passed since this question... Is this still valid?
I.e. Keyword arguments are not supported for refelction based callers?

I am implementing the caller side for an application and all the arguments are passed as keyword arguments. So it would make my life easier :)

Thank you very much.

@darkl
Copy link
Member

darkl commented Dec 4, 2020

Hi @Chunky-Monkey,
I never implemented such feature. As stated above, I support adding an attribute which indicates whether all arguments should be treated as keyword arguments/positional arguments.

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

No branches or pull requests

3 participants