dolcenum

Make Python enums sweeter by adding the member docstring to each member.

Classes

class pymisclib.dolcenum.DolcEnumMeta(name: str, bases: tuple[type, ...], attrs: _EnumDict)

Metaclass to assign member docstrings to the enum members.

The metaclass is assigned to the metaclass attribute in the enum class definition. The class itself and each member must have a docstring (or there must be no docstrings whatsoever.)

Raises:

ValueError – One or more docstrings are missing.

Example

import enum
from pymisclib.dolcenum import DolcEnumMeta


@enum.unique
class MyEnum(enum.IntEnum, metaclass=DolcEnumMeta):
    """Class MyEnum docstring."""
    A = enum.auto()
    """Member MyEnum.A docstring."""
    B = enum.auto()
    """Member MyEnum.B docstring."""
    C = enum.auto()
    """Member MyEnum.C docstring."""


for e in MyEnum:
    print(f'{e.name}:{e.value} "{e.__doc__}"')
class pymisclib.dolcenum.MissingDocstringError

DoclEnumMeta-derived enum is missing one or more docstrings.