pyiron / pyiron_workflow

Graph-and-node based workflows
BSD 3-Clause "New" or "Revised" License
10 stars 1 forks source link

Multiple dispatch decorators #317

Open liamhuber opened 1 month ago

liamhuber commented 1 month ago

The following two should be equivalent

@Worfklow.wrap.as_function_node()
def foo(x):
    y = y + 1
    return y

and

@Worfklow.wrap.as_function_node
def foo(x):
    y = y + 1
    return y

But you should, of course, still be able to provide labels (or kwargs, if the decorator takes them) if you want

@Worfklow.wrap.as_function_node("something_other_than_y")
def foo(x):
    y = y + 1
    return y

And similarly for macros and any other decorators that don't have required arguments -- which is all of them so far.

This should be doable, at least for the macro and function node decorators, by parsing the *args to see whether it is zero length, or whether it is length 1 but the value is a callable rather than a string, and just decorating directly.