FunctionDeclaration
A Python function declaration.
import { FunctionDeclaration } from "@alloy-js/python";
<FunctionDeclaration args async classFunction doc={Children} instanceFunction kwargs name="string" parameters={ParameterDescriptor[] | string[]} refkey={Refkey | Refkey[]} returnType={Children} typeParameters={string[]} />
import { FunctionDeclaration } from "@alloy-js/python/stc";
FunctionDeclaration({ args: boolean, async: boolean, classFunction: boolean, doc: Children, instanceFunction: boolean, kwargs: boolean, name: string, parameters: ParameterDescriptor[] | string[], refkey: Refkey | Refkey[], returnType: Children, typeParameters: string[],}).children(children)
args | optionalboolean Indicates if there are positional arguments ( |
async | optionalboolean |
children | optionalChildren |
classFunction | optionalboolean Indicates that this is a class function. |
doc | optionalChildren Documentation for this declaration |
instanceFunction | optionalboolean Indicates that this is an instance function. |
kwargs | optionalboolean Indicates if there are keyword arguments ( |
name | string The base name of this declaration. May change depending on naming policy and any conflicts. |
parameters | optionalParameterDescriptor[] | string[] The parameters to the call signature. Can be an array of strings for parameters which don’t have a type or a default value. Otherwise, it’s an array of ParameterDescriptors. |
refkey | optionalRefkey | Refkey[] The refkey or array of refkeys for this declaration. |
returnType | optionalChildren The return type of the function. |
typeParameters | optionalstring[] The type parameters of the call signature, e.g. for a generic function. This is only supported in Python 3.12+. |
Example
Section titled “Example”<FunctionDeclaration name="my_function" returnType="int" parameters=[{name: "a", type: "int"},{name: "b", type: "str"}]> return a + b</FunctionDeclaration>
This will generate:
def my_function(a: int, b: str) -> int: return a + b