General API design - callbacks
Posted: Fri Sep 27, 2013 4:38 pm
So what do you think is the best method to specify callbacks?
Just a single method or support args/kwargs?
vs
Please note that with both solutions you can use arguments, except you need a wrapper for the first like this:
Just a single method or support args/kwargs?
Syntax: Select all
def myapifunc(callback):
callback()
vs
Syntax: Select all
def myapifunc(callback, callback_args=(), callback_kwargs={}):
callback(*callback_args, **callback_kwargs)
Please note that with both solutions you can use arguments, except you need a wrapper for the first like this:
Syntax: Select all
class Wrap(object):
def __init__(self, callback, args, kwargs):
self.callback = callback
self.args = args
self.kwargs = kwargs
def __call__(self):
self.callback(*self.args, **self.kwargs)