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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file enum-prop-0.0.1.tar.gz.

File metadata

  • Download URL: enum-prop-0.0.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for enum-prop-0.0.1.tar.gz
Algorithm Hash digest
SHA256 77edfd912c1dfe795e9584b83b4c6890b993f33e3c7e59ec2d522f4ed8ae9167
MD5 a8ff4b86ee9e315a3eeb7922fad4d080
BLAKE2b-256 d313b0988c1f83d4dea2bfdbc7b162ed4e27dc7d85eae66eb28421fa615df863

See more details on using hashes here.

File details

Details for the file enum_prop-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: enum_prop-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for enum_prop-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fe9a4a017f1bda19455018c05b212c2589f1d2dbea472dd6aa727d03458e4eda
MD5 25977689c53124bbd7666ac495cee559
BLAKE2b-256 0aea4a1817780a77b744e3642fda48c4785fd7ba176f797abbe890f45434748f

See more details on using hashes here.

Supported by

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