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 to Dispatcher.add_function().

The workhorse is the addme() which delegates to Dispatcher.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 of Dispatcher.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, on addme(), 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)

digraph dmap { graph [ratio=1] node [style=filled] label = <dmap> splines = ortho style = filled 297 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-364ce5fc5ee60d138c76dcdcaccd918678cb817e/lambda.html">&lt;lambda&gt;(&#x27;num&#x27;, &#x27;num2&#x27;) --&gt; (&#x27;res2&#x27;,)</TD></TR><TR><TD align="RIGHT" border="1">weight</TD><TD align="LEFT" border="1">30</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="<lambda>('num', 'num2') --> ('res2',)"] 298 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-364ce5fc5ee60d138c76dcdcaccd918678cb817e/lambda-0.html">&lt;lambda&gt;(&#x27;num&#x27;,) --&gt; (&#x27;res&#x27;,)</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="<lambda>('num',) --> ('res',)"] 299 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-364ce5fc5ee60d138c76dcdcaccd918678cb817e/lambda-1.html">&lt;lambda&gt;(&#x27;res&#x27;, &#x27;res1&#x27;) --&gt; [&#x27;nargs&#x27;, &#x27;res22&#x27;]</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="<lambda>('res', 'res1') --> ['nargs', 'res22']"] 300 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">nargs</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip=nargs] 301 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">num</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip=num] 302 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">num2</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip=num2] 303 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">res</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip=res] 304 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">res1</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip=res1] 305 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">res2</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip=res2] 306 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">res22</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip=res22] 299 -> 306 302 -> 297 297 -> 305 303 -> 299 304 -> 299 301 -> 297 298 -> 303 301 -> 298 299 -> 300 }

Methods

__init__ Initialize self.
add_dfuns
addme
copy
inspect_inputs
__init__(out, fun, inputs=None, **kwds)[source]

Initialize self. See help(type(self)) for accurate signature.