Skip to content

EnumDeclaration

A Python enum declaration, following https://docs.python.org/3.11/library/enum.html.

import { EnumDeclaration } from "@alloy-js/python";
<EnumDeclaration
baseType={"Enum" | "IntEnum" | "StrEnum" | "Flag" | "IntFlag"}
doc={Children}
doc={Children}
members={Array<{
name: string;
value?: Children;
jsValue?: string | number;
doc?: string;
}>}
name="string"
refkey={Refkey | Refkey[]}
style={"classic" | "auto" | "functional"}
/>
baseTypeoptional”Enum” | “IntEnum” | “StrEnum” | “Flag” | “IntFlag”

The base type of the enum. One of: ‘Enum’, ‘IntEnum’, ‘StrEnum’, ‘Flag’, ‘IntFlag’. Defaults to ‘Enum’.

childrenoptionalChildren
docoptionalChildren

Optional docstring for the enum.

docoptionalChildren

Documentation for this declaration

membersoptionalArray<{ name: string; value?: Children; jsValue?: string | number; doc?: string; }>

Members of the enum as an array of objects.

namestring

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

refkeyoptionalRefkey | Refkey[]

The refkey or array of refkeys for this declaration.

styleoptional”classic” | “auto” | “functional”

The enum style: ‘classic’ (default), ‘auto’, or ‘functional’.

<EnumDeclaration name="Direction" style="functional">
members={[
{ name: "NORTH" },
{ name: "SOUTH" },
{ name: "EAST" },
{ name: "WEST" },
]}
/>

This will generate:

from enum import Enum
class Direction(Enum):
NORTH = "NORTH"
SOUTH = "SOUTH"
EAST = "EAST"
WEST = "WEST"