7.2.6.16. DFun¶
-
class
DFun
(out, fun, inputs=None, **kwds)[source]¶ A 3-tuple
(out, fun, **kwds)
, used to prepare a list of calls toDispatcher.add_function()
.The workhorse is the
addme()
which delegates toDispatcher.add_function()
:out
: a scalar string or a string-list that, sent as output arg,fun
: a callable, sent as function args,kwds
: any keywords ofDispatcher.add_function()
.Specifically for the ‘inputs’ argument, if present in kwds, use them (a scalar-string or string-list type, possibly empty), else inspect function; in any case wrap the result in a tuple (if not already a list-type).
Note
Inspection works only for regular args, no
*args, **kwds
supported, and they will fail late, onaddme()
, if no input or inp defined.
Example:
>>> dfuns = [ ... DFun('res', lambda num: num * 2), ... DFun('res2', lambda num, num2: num + num2, weight=30), ... DFun(out=['nargs', 'res22'], ... fun=lambda *args: (len(args), args), ... inputs=('res', 'res1') ... )] >>> dfuns [DFun('res', <function <lambda> at 0x...>, ), DFun('res2', <function <lambda> at 0x...>, weight=30), DFun(['nargs', 'res22'], <function <lambda> at 0x...>, inputs=('res', 'res1'))] >>> from schedula import Dispatcher >>> dsp = Dispatcher() >>> DFun.add_dfuns(dfuns, dsp)
Methods
__init__
Initialize self. add_dfuns
addme
copy
inspect_inputs