Skip to content

InitFunctionDeclaration

A Python __init__ function declaration.

import { InitFunctionDeclaration } from "@alloy-js/python";
<InitFunctionDeclaration />

This is a convenience component that sets the name to __init__, marks it as an instance function, and forces the name to be __init__ without applying the name policy.

<InitFunctionDeclaration>
self.attribute = "value"
</InitFunctionDeclaration>

This will generate:

def __init__(self: MyClass) -> None:
self.attribute = "value"