Skip to content

Using Method in Flow

In this section, you'll learn how to use methods withing the flow. We'll expand the "Hello World" example by adding a method to the flow.

Syntax

flow HelloWorld_UsingMethod -> None:
    method greet using constant
flows/hello_world_using_method_fy.py
"""fy
flow HelloWorld_UsingMethod -> None:
    method greet using constant
"""

from fy_core.base.flow_base import FlowBase

from mixins.methods.greet.using_constant_fy import (
    Greet_UsingConstant_MethodMixin,
)


# fy:start ===>>>
class HelloWorld_UsingMethod_Flow(
    # Method Mixins
    Greet_UsingConstant_MethodMixin,
    # Base
    FlowBase[None],
):
    def __call__(self) -> None:
        # fy:end <<<===
        self._greet()

Breakdown of Syntax

  1. flow HelloWorld_UsingMethod -> None:
    • Declares a new flow named HelloWorld_UsingMethod, which represents a Python class.
    • -> None specifies that the flow does not return a value.
  2. method greet using constant
    • Defines a mixin inclusion in the flow that tells the fy tool that the flow class has to inherit the method mixin class.
  3. Code Generation:
    • Everything between # fy:start and # fy:end is automatically generated by the fy tool.
    • The generated code includes the class definition HelloWorld_Flow, which incorporates the Greet_UsingConstant_MethodMixin mixin and the FlowBase base class.
    • fy tool adds necessary imports, such as Greet_UsingConstant_MethodMixin, which contains the greet method, and FlowBase for flow base class functionality. It adds imports only when they do not exist.
    • The __call__ method calls the _greet method.
  4. User Input:
    • The only code the user needs to write is the flow declaration within the """fy block. After generation, the user can add custom logic, such as self._greet().