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 | Namekey}
omitNone
refkey={Refkey | Refkey[]}
type={Children}
/>
callStatementVaroptional booleanIndicates if this is a call statement variable. Optional. This is used to handle cases where the variable is part of a call statement.
childrenoptional Children
docoptional ChildrenDocumentation for this declaration
initializeroptional ChildrenThe initial value of the variable.
instanceVariableoptional booleanIndicates if this variable is an instance variable. Optional. This is used to handle cases where the variable is part of a class instance.
namestring | NamekeyThe base name of this declaration. May change depending on naming policy and any conflicts.
omitNoneoptional booleanIndicates if we should omit the None assignment. Optional.
refkeyoptional Refkey | Refkey[]The refkey or array of refkeys for this declaration.
typeoptional ChildrenThe 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