VariableDeclaration
A variable declaration component for Python.
import { VariableDeclaration } from "@alloy-js/python";
<VariableDeclaration callStatementVar doc={Children} initializer={Children} instanceVariable name={string | Namekey} omitNone refkey={Refkey | Refkey[]} type={Children} />import { VariableDeclaration } from "@alloy-js/python/stc";
VariableDeclaration({ callStatementVar: boolean, doc: Children, initializer: Children, instanceVariable: boolean, name: string | Namekey, omitNone: boolean, refkey: Refkey | Refkey[], type: Children,}).children(children)| callStatementVar | optional boolean | Indicates if this is a call statement variable. Optional. This is used to handle cases where the variable is part of a call statement. |
| children | optional Children | |
| doc | optional Children | Documentation for this declaration |
| initializer | optional Children | The initial value of the variable. |
| instanceVariable | optional boolean | Indicates if this variable is an instance variable. Optional. This is used to handle cases where the variable is part of a class instance. |
| name | string | Namekey | The base name of this declaration. May change depending on naming policy and any conflicts. |
| omitNone | optional boolean | Indicates if we should omit the None assignment. Optional. |
| refkey | optional Refkey | Refkey[] | The refkey or array of refkeys for this declaration. |
| type | optional Children | The type of the variable. Used only for type annotation. Optional. |
Example
Section titled “Example”<VariableDeclaration
name="myVar"
type="int"
initializer={42} // Initial value
/>
<VariableDeclaration
name="myOtherVar"
type="str"
omitNone={true}
/>
<VariableDeclaration
name="myCallStmtVar"
callStatementVar={true}
initializer={12}
/>
VariableDeclaration
name=""
callStatementVar={true}
initializer={12}
/>
renders to
myVar: int = 42
myOtherVar: str
myCallStmtVar=12
12