https://github.com/5monkeys/enum-prop
https://github.com/5monkeys/enum-prop
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/5monkeys/enum-prop
- Owner: 5monkeys
- License: bsd-3-clause
- Created: 2021-08-18T08:29:40.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-11-22T12:44:01.000Z (over 4 years ago)
- Last Synced: 2025-02-28T08:55:38.368Z (over 1 year ago)
- Language: Python
- Size: 12.7 KB
- Stars: 0
- Watchers: 5
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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
```shell
$ python3 -m pip install enum-prop
```
### Usage
```python
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
```