Skip to content Skip to sidebar Skip to footer

How Do I Properly Document Python Enum Elements?

I understand that I can add a Python docstring to an enum type as I would any other class. But how do I add documentation to an element of that type? As far as I can see there are

Solution 1:

If the values themselves are not important, see How do I put docstrings on Enums?. If the values are important you can either customize that answer or use the aenum library:

from aenumimport Enum

class MyEnum(Enum):
    _init_ = 'value __doc__'
    a = 0, 'docstringfora'
    b = 1, 'anotherforb'
    c = 2, 'and one forcas well'

which results in:

>>>MyEnum.b.value
1
>>>MyEnum.b.__doc__
'another for b'

However, I do not know which, if any, IDEs support using Enum member doc strings.


Disclosure: I am the author of the Python stdlib Enum, the enum34 backport, and the Advanced Enumeration (aenum) library.

Post a Comment for "How Do I Properly Document Python Enum Elements?"