FunctionalEnumDeclaration
Create a Python enum using the functional syntax.
This generates enums using the Enum('Name', [...])
or Enum('Name', {...})
syntax.
The format depends on whether enum members have explicit values:
- Members without values:
Enum('Direction', ['NORTH', 'SOUTH', 'EAST', 'WEST'])
- Members with values:
Enum('Direction', {'NORTH': 1, 'SOUTH': 2, 'EAST': 3, 'WEST': 4})
import { FunctionalEnumDeclaration } from "@alloy-js/python";
<FunctionalEnumDeclaration baseType={"Enum" | "IntEnum" | "StrEnum" | "Flag" | "IntFlag"} doc={Children} members={Array<EnumMemberProps>} />
import { FunctionalEnumDeclaration } from "@alloy-js/python/stc";
FunctionalEnumDeclaration({ baseType: "Enum" | "IntEnum" | "StrEnum" | "Flag" | "IntFlag", doc: Children, members: Array<EnumMemberProps>,}).children(children)
baseType | optional”Enum” | “IntEnum” | “StrEnum” | “Flag” | “IntFlag” The base type of the enum. One of: ‘Enum’, ‘IntEnum’, ‘StrEnum’, ‘Flag’, ‘IntFlag’. Defaults to ‘Enum’. |
doc | optionalChildren Optional docstring for the enum. |
members | optionalArray<EnumMemberProps> Members of the enum as an array of objects. |
Examples
Section titled “Examples”<FunctionalEnumDeclaration name="Direction" members={[ { name: "NORTH" }, { name: "SOUTH" }, { name: "EAST" }, { name: "WEST" } ]}/>
renders to:
Direction = Enum('Direction', ['NORTH', 'SOUTH', 'EAST', 'WEST'])
<FunctionalEnumDeclaration name="Status" members={[ { name: "PENDING", value: 1 }, { name: "ACTIVE", value: 2 }, { name: "INACTIVE", value: 3 } ]}/>
renders to:
Status = Enum('Status', {'PENDING': 1, 'ACTIVE': 2, 'INACTIVE': 3})