Skip to content

MethodDeclaration

A Python instance method declaration component.

Shared base props for all method-like declarations.

import { MethodDeclaration } from "@alloy-js/python";
<MethodDeclaration abstract async />
abstractoptionalboolean

Indicates that the method is abstract.

asyncoptionalboolean

Indicates that the function is async.

Automatically injects the self parameter for instance methods and enforces that the declaration appears within a class body.

<py.MethodDeclaration name="do_work" parameters={[{ name: "value", type: "int" }]}>
return value * 2
</py.MethodDeclaration>

Generates:

def do_work(self, value: int) -> None:
return value * 2