A utility package for extending, subclassing and reusing Enum classes.
Likely abandoned. No release or commit for years (last release over 4 years ago).
pip install extendable-enumExtendable Enum
extendableenum is a simple package for extending, subclassing and reusing python Enum classes.
It contains four class decorators and a single class:
inheritable_enum- Enum class decorator. Makes the class and all its members inheritable. Subclassing enums can define new members while still having access to the base class members.auto_null_member- Enum class decorator. Automatically adds the null member to an enum class. If the class doesn't define any other enum members, also becomes an inheritable enum. The auto null member name and value can be set with theset_auto_nullfunction. Default name/value isNULL/None.post_mixin_enum- Enum class decorator. Adds the decorated class as a base class to an existing enum. Allows extending an enum class with methods after creation.copy_enum_members- Enum class decorator. Creates a new and distinct enum class with the same members as an existing enum. New enum can optionally define additional members.AutoNullEnum- A base class for enum classes using the auto null feature. Contains convenience functions for dealing with the auto null member.
Documentation
Full documentation for the package can be found on read the docs
Installation
Install with pip:
pip install extendable-enum
Requirements
- Python 3.6+
- This version was auto-detected by the vermin package. This is yet to be verified.
Examples
Basic usage and examples can be found here. For in depth behaviour and advanced usage, see the docs.
Inheritable Enums
from enum import Enum
from extendableenum import inheritable_enum
@inheritable_enum
class Base(Enum):
A = 1
B = 2
# Subclass Base, define new members and an aliases.
class Derived(Base):
ALIAS_B = 2
C = 3
D = 4
Base.restore() # Base now behaves as if it were never decorated.
Auto Null Member
Create An Enum with the Null Member
from enum import Enum
from extendableenum import auto_null_member, set_auto_null
# optional: specify null member name and value
set_auto_null('NULL', None) # this is the default name/value
@auto_null_member
class Fruit(Enum):
APPLE = 1
BANANA = 2
PEAR = 3
print(f'{Fruit.NULL.name}, {Fruit.NULL.value}')
>>> NULL, None