Tidy enum properties
Project description
enum-prop
Enum definitions can't, for good reasons, reference instances of themselves within their own definitions. This module allows definitions to come around that by mapping the names of enums for lookups, hidden behind a special dict subclass. This allows enum definitions to remain tidy, and avoids having to define instance-specific configuration as property functions.
Installation
$ python3 -m pip install enum-prop
Usage
import enum
from enum_prop import enum_property, enum_getter
class Vehicle(enum.Enum):
car = "car"
bike = "bike"
unicycle = "unicycle"
wheels = enum_property({car: 4, bike: 2, unicycle: 1})
__int__ = enum_getter({car: 4, bike: 2, unicycle: 1})
print(Vehicle.unicycle.wheels) # 1
print(Vehicle.car.wheels) # 4
print(int(Vehicle.unicycle)) # 1
print(int(Vehicle.bike)) # 2
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
enum-prop-0.0.1.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for enum_prop-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe9a4a017f1bda19455018c05b212c2589f1d2dbea472dd6aa727d03458e4eda |
|
MD5 | 25977689c53124bbd7666ac495cee559 |
|
BLAKE2b-256 | 0aea4a1817780a77b744e3642fda48c4785fd7ba176f797abbe890f45434748f |