ClassMethodDeclaration
A Python class method declaration component.
import { ClassMethodDeclaration } from "@alloy-js/python";
<ClassMethodDeclaration abstract async decorators={Children[]} />import { ClassMethodDeclaration } from "@alloy-js/python/stc";
ClassMethodDeclaration({ abstract: boolean, async: boolean, decorators: Children[],}).children(children)| abstract | optional boolean | |
| async | optional boolean | Indicates that the function is async. |
| decorators | optional 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. |