Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Subclassing flows #2035

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

simonwardjones
Copy link

@simonwardjones simonwardjones commented Sep 17, 2024

Currently it is not possible to subclass a Flow as in the example snippet below.

This PR alters the graph construction that enables this flow subclassing. Instead of using the ast.NodeVisitor class to collect the steps and their ast.FunctionDef's. I have instead iterated on the dir(flow) and then extracted the function ast.FunctionDef's.

from metaflow import FlowSpec, step


class BaseFlow(FlowSpec):
    @step
    def start(self):
        print("this is the start")
        self.next(self.step1)

    @step
    def step1(self):
        print("base step 1")
        self.next(self.end)

    @step
    def end(self):
        print("base step end.")


class SubFlow(BaseFlow):
    @step
    def step1(self):
        print("sub step 1")
        self.next(self.step2)

    @step
    def step2(self):
        print("sub step 2")
        self.next(self.end)


if __name__ == "__main__":
    SubFlow()

As referenced in this issue: #144
and discussed in this issue: #245

I have not yet added tests for this PR as the approach to this might take some discussion. The current Test harness setup uses the FlowFormatter class to generate flows on the fly but all of these assume the flow directly inherits off the FlowSpec. How might we go about testing this kind of subclassing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant