Skip to content

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}
/>
callStatementVaroptionalboolean

Indicates if this is a call statement variable. Optional. This is used to handle cases where the variable is part of a call statement.

childrenoptionalChildren
docoptionalChildren

Documentation for this declaration

initializeroptionalChildren

The initial value of the variable.

instanceVariableoptionalboolean

Indicates if this variable is an instance variable. Optional. This is used to handle cases where the variable is part of a class instance.

namestring

The base name of this declaration. May change depending on naming policy and any conflicts.

omitNoneoptionalboolean

Indicates if we should omit the None assignment. Optional.

refkeyoptionalRefkey | Refkey[]

The refkey or array of refkeys for this declaration.

typeoptionalChildren

The type of the variable. Used only for type annotation. Optional.

<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