Skip to content

DunderMethodDeclaration

A Python dunder method declaration.

import { DunderMethodDeclaration } from "@alloy-js/python";
<DunderMethodDeclaration abstract async decorators={Children[]} />
abstractoptional boolean
asyncoptional booleanIndicates that the function is async.
decoratorsoptional Children[]Decorators rendered above def, in source order — decorators[0] is topmost. By Python’s bottom-up application order, the topmost entry is the outermost decorator (applied last) and wraps the result of every decorator below it. Each entry should produce a complete decorator line (typically starting with @). Falsy entries (other than 0) are skipped, so conditional decorators can be provided inline when needed. When used through wrappers that emit an intrinsic decorator (ClassMethodDeclaration@classmethod, StaticMethodDeclaration@staticmethod, PropertyDeclaration@property), these decorators are rendered above the intrinsic line — the correct position for Pydantic’s @field_validator / @model_validator and other wrappers that must see the underlying function, not a descriptor. When used on plain MethodDeclaration / FunctionDeclaration, these decorators are rendered above @abstractmethod (if abstract is set) and above def. Do not pass intrinsic decorators here — i.e. @classmethod, @staticmethod, @property, or @abstractmethod. Those are emitted by the matching component (ClassMethodDeclaration, StaticMethodDeclaration, PropertyDeclaration, or the abstract flag) and would otherwise be stacked twice in the output, producing invalid Python.