Skip to content

Parsing dataclass construction #271

Description

@liamhuber

Dataclasses are just callables, and for a given dataclass one can straightforwardly construct an unambiguous atomic recipe to transform individual inputs -> dataclass instance outputs. Thus, it would be nice to be able to parse workflows like:

import dataclasses
import flowrep as fr

@fr.dataclass
class Payload:
    item: str
    multiple: int

def order(payload: Payload):
    to_buy = f"Please buy {payload.multiple} {payload.item}s"

@fr.workflow
def shopping_for_two(item, n):
    p = Payload(item, n)
    to_buy = order(p)
    return to_buy

I think if @fr.dataclass attaches a .flowrep_recipe: AtomicRecipe, and a partial function for that recipe to reference, this should work out-of-the-box. Compiling it might be slightly more of a headache, but I think it's just bookkeeping and not any fundamental obstacle.

I've already done something similar in pyiron_workflow to overload dataclasses.dataclass with workflow power-ups, so I know it's very doable and should be able to mostly just port parts of that solution here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementCategory: New feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions