FunctionDeclaration
A Python function declaration.
import { FunctionDeclaration } from "@alloy-js/python";
<FunctionDeclaration async />
import { FunctionDeclaration } from "@alloy-js/python/stc";
FunctionDeclaration({ async: boolean }).children(children)
async | optionalboolean Indicates that the function is async. |
Remarks
Section titled “Remarks”This component creates a Python function declaration with optional type annotations, parameters, and return types. It supports async functions and automatically handles symbol creation and emission.
Example
Section titled “Example”<FunctionDeclaration name="my_function" returnType="int" parameters={[{ name: "a", type: { children: "int" } }, { name: "b", type: { children: "str" } }]}> return a + b</FunctionDeclaration>
This will generate:
def my_function(a: int, b: str) -> int: return a + b