Extends the capabilities of the standard Enum.
Project description
extended-enum
Introduction
Package that expands the capabilities of the standard Enum.
Features
- store additional information inside Enum member
Install
pip install extended-enum
Usage
Quick Start
from dataclasses import dataclass, field
from enum import unique
from typing import Optional
from uuid import UUID
from extended_enum import ExtendedEnum, ValueWithDescription, BaseExtendedEnumValue, EnumField
@dataclass(frozen=True)
class SomeExtendedEnumValue(BaseExtendedEnumValue):
display_name: str = field(compare=False)
description: Optional[str] = field(default=None, compare=False)
class MixedEnum(ExtendedEnum):
"""A combined enumeration in which member values are of different types."""
CONST1 = EnumField('const1')
CONST2 = EnumField(1)
CONST3 = EnumField(UUID('79ff3431-3e98-4bec-9a4c-63ede2580f83'))
NOT_DUPLICATE_CONST3 = EnumField('79ff3431-3e98-4bec-9a4c-63ede2580f83')
CONST4 = EnumField(BaseExtendedEnumValue(value='const4'))
CONST5 = EnumField(BaseExtendedEnumValue(value=2))
CONST6 = EnumField(BaseExtendedEnumValue(value=UUID('e7b4b8ae-2224-47ec-afce-40aeb10b85e2')))
CONST7 = EnumField(ValueWithDescription(value='const7'))
CONST8 = EnumField(ValueWithDescription(value=3, description='some const8 description'))
CONST9 = EnumField(SomeExtendedEnumValue(value='const9', display_name='some display name', description='some const9 description'))
unique(MixedEnum)
>>> MixedEnum.CONST9
<MixedEnum.CONST9: SomeExtendedEnumValue(value='const9', display_name='some display name', description='some const9 description')>
>>> MixedEnum.CONST9.value
'const9'
>>> MixedEnum.CONST9.extended_value
SomeExtendedEnumValue(value='const9', display_name='some display name', description='some const9 description')
>>> MixedEnum.get_values()
Tuple
('const1',
1,
UUID('79ff3431-3e98-4bec-9a4c-63ede2580f83'),
'79ff3431-3e98-4bec-9a4c-63ede2580f83',
'const4',
2,
UUID('e7b4b8ae-2224-47ec-afce-40aeb10b85e2'),
'const7',
3,
'const9')
>>> MixedEnum.get_extended_values()
Tuple
(BaseExtendedEnumValue(value='const1'),
BaseExtendedEnumValue(value=1),
BaseExtendedEnumValue(value=UUID('79ff3431-3e98-4bec-9a4c-63ede2580f83')),
BaseExtendedEnumValue(value='79ff3431-3e98-4bec-9a4c-63ede2580f83'),
BaseExtendedEnumValue(value='const4'),
BaseExtendedEnumValue(value=2),
BaseExtendedEnumValue(value=UUID('e7b4b8ae-2224-47ec-afce-40aeb10b85e2')),
ValueWithDescription(value='const7', description=None),
ValueWithDescription(value=3, description='some const8 description'),
SomeExtendedEnumValue(value='const9', display_name='some display name', description='some const9 description'))
License
This project is licensed under the Apache-2.0 License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
extended_enum-1.0.3.tar.gz
(7.8 kB
view hashes)
Built Distribution
Close
Hashes for extended_enum-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ba97f3c5d09c58451dd0b36122d4fb5c75e147c56a279392fe791779a75f8ed |
|
MD5 | dd8d6d0f91db59e208d66079da0cede9 |
|
BLAKE2b-256 | f53d9a2a6a8436ebfa846dcd366c46cd630964c098e7a2ce5104a1e383058e27 |