VariableDeclaration
A variable declaration component for Python.
import { VariableDeclaration } from "@alloy-js/python";
<VariableDeclaration callStatementVar doc={Children} initializer={Children} instanceVariable name="string" omitNone refkey={Refkey | Refkey[]} type={Children} />
import { VariableDeclaration } from "@alloy-js/python/stc";
VariableDeclaration({ callStatementVar: boolean, doc: Children, initializer: Children, instanceVariable: boolean, name: string, omitNone: boolean, refkey: Refkey | Refkey[], type: Children,}).children(children)
callStatementVar | optionalboolean 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 | optionalChildren |
doc | optionalChildren Documentation for this declaration |
initializer | optionalChildren The initial value of the variable. |
instanceVariable | optionalboolean 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 The base name of this declaration. May change depending on naming policy and any conflicts. |
omitNone | optionalboolean Indicates if we should omit the None assignment. Optional. |
refkey | optionalRefkey | Refkey[] The refkey or array of refkeys for this declaration. |
type | optionalChildren 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 = 42myOtherVar: strmyCallStmtVar=1212