ClassDeclaration
Create a Python class declaration.
import { ClassDeclaration } from "@alloy-js/python";
<ClassDeclaration bases={Children[]} doc={Children} name={string | Namekey} refkey={Refkey | Refkey[]} />import { ClassDeclaration } from "@alloy-js/python/stc";
ClassDeclaration({ bases: Children[], doc: Children, name: string | Namekey, refkey: Refkey | Refkey[],}).children(children)| bases | optional Children[] | The base classes that this class inherits from. |
| children | optional Children | |
| doc | optional Children | Documentation for this declaration |
| name | string | Namekey | The base name of this declaration. May change depending on naming policy and any conflicts. |
| refkey | optional Refkey | Refkey[] | The refkey or array of refkeys for this declaration. |
Remarks
Section titled “Remarks”Any child declarations (methods, fields, nested classes) will be placed in the class scope. This component creates a class scope to hold its members.
Example
Section titled “Example”<ClassDeclaration name="MyClass" bases={["BaseClass"]}>
<VariableDeclaration name="a" type="int" />
<VariableDeclaration name="b" type="str" />
<py.FunctionDeclaration name="my_method" parameters={[{ name: "a", type: "int" }, { name: "b", type: "str" }]} returnType="int">
return a + b
</py.FunctionDeclaration>
</ClassDeclaration>
renders to
class MyClass(BaseClass):
a: int = None
b: str = None
def my_method(self, a: int, b: str) -> int:
return a + b