Kwargs in messenger

Is keyword arguments supported in messenger?

   def some_function(self, a=1, b=2, c=3):
       some function
   messenger.send('event name', [c=5]) 

in the above example, is it possible to pass specific variable values?
or the only solution would be messenger.send('event name', [1,2,5]) ?

This is not supported at the moment. Do you have a use case where this is necessary?

Instead of relying on kwargs, you could pass a dictionary:

def some_function(self, args_dict):
    defaults = {'a':1, 'b':2, 'c':3}
    args_dict = defaults.update(args_dict)
messenger.send('event name', [{'c':5}])

This isn’t as clean as kwargs, but it should do the trick.

1 Like

That said, it would not be particularly hard to add this feature, so feel free to add this as a feature request, if you can show a good use case.

Not necessary, was just thinking a clean way to pass specific arguments in messenger.
But I think Moguri’s solution was a clean and elegant alternative to **kwargs!! :+1:

could definitely use this. Passing a dict is fine in most cases but not as pythonic :wink:

However, I am also currently hooking into some other code which uses the **kwargs magic and I need to create a dict handler to pass to my functions

Example:

def messyKwargPasser(f, arglist, kwargdict):
     return f(*arglist,**kwargdict) 

def foo(*args,**kwargs):
    print("args: ", args)
    print("kwargs: ", kwargs)

base.accept("mouse1", messyKwargPasser, extraArgs = [ foo, ['hello' ], {'well':'hi there'} ] )

would be nice to have some functionality like

base.accept("mouse1", foo , extraArgs = ["hello"], extraKwargs = {'well':'hi there'} )