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 | optionalbooleanIndicates 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 | optionalChildrenDocumentation for this declaration |
| initializer | optionalChildrenThe initial value of the variable. |
| instanceVariable | optionalbooleanIndicates 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 | NamekeyThe base name of this declaration. May change depending on naming policy and any conflicts. |
| omitNone | optionalbooleanIndicates if we should omit the None assignment. Optional. |
| refkey | optionalRefkey | Refkey[]The refkey or array of refkeys for this declaration. |
| type | optionalChildrenThe 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