nodify.nodify_func

nodify.nodify_func(func: ~types.LambdaType, transformer_cls: ~typing.Type[~nodify.parse.NodeConverter] = <class 'nodify.parse.NodeConverter'>, assign_fn: ~typing.Callable | None = None, node_cls: ~typing.Type[~nodify.node.Node] = <class 'nodify.node.Node'>) LambdaType[source]

Converts all calculations of a function into nodes.

This is used for example to convert a function into a workflow.

The conversion is done by getting the function’s source code, parsing it into an abstract syntax tree, modifying the tree and recompiling.

Parameters:
  • func (Callable) – The function to convert.

  • transformer_cls (Type[NodeConverter], optional) – The NodeTransformer class to that is used to transform the AST.

  • assign_fn (Union[Callable, None], optional) –

    A function that will be placed as middleware for variable assignments. It will be called with the following arguments:

    • value: The value assigned to the variable.

    • var_name: The name of the variable that will be assigned.

  • node_cls (Type[Node], optional) – The Node class to which function calls will be converted.