MethodDeclaration
A Python instance method declaration component.
Shared base props for all method-like declarations.
import { MethodDeclaration } from "@alloy-js/python";
<MethodDeclaration abstract async />
import { MethodDeclaration } from "@alloy-js/python/stc";
MethodDeclaration({ abstract: boolean, async: boolean }).children(children)
abstract | optionalboolean Indicates that the method is abstract. |
async | optionalboolean Indicates that the function is async. |
Remarks
Section titled “Remarks”Automatically injects the self
parameter for instance methods and enforces
that the declaration appears within a class body.
Example
Section titled “Example”<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