Skip to main content

Tidy enum properties

Project description

enum-prop

CI Build Status

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


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)

Uploaded Source

Built Distribution

enum_prop-0.0.1-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page