Skip to content

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[]}
/>
argsoptionalboolean

Indicates if there are positional arguments (*args) in the function

asyncoptionalboolean
childrenoptionalChildren
classFunctionoptionalboolean

Indicates that this is a class function.

docoptionalChildren

Documentation for this declaration

instanceFunctionoptionalboolean

Indicates that this is an instance function.

kwargsoptionalboolean

Indicates if there are keyword arguments (**kwargs) in the function

namestring

The base name of this declaration. May change depending on naming policy and any conflicts.

parametersoptionalParameterDescriptor[] | 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.

refkeyoptionalRefkey | Refkey[]

The refkey or array of refkeys for this declaration.

returnTypeoptionalChildren

The return type of the function.

typeParametersoptionalstring[]

The type parameters of the call signature, e.g. for a generic function. This is only supported in Python 3.12+.

<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