def add_int_enums_to_docstring(enum):
    """Decorator for IntEnum which re-writes the documentation string so that
    Sphinx enumerates all the enumeration values.

    This is a work-around for Sphinx autodoc's inability to properly document
    IntEnums.

    This decorator adds enumeration names and values to the 'Attributes'
    section of the docstring of the decorated IntEnum class.

    Example::

        >>> from enum import IntEnum
        >>> @add_int_enums_to_docstring
        ... class MyIntEnum(IntEnum):
        ...     '''An example IntEnum.'''
        ...     a = 0
        ...     b = 1
        >>> print(MyIntEnum.__doc__)
        An example IntEnum.
        <BLANKLINE>
        Attributes
        ----------
        a = 0
        b = 1
        <BLANKLINE>
    """
    if enum.__doc__ is None:
        enum.__doc__ = ''
    enum.__doc__ += '\n\nAttributes\n----------\n'
    for val in list(enum):
        enum.__doc__ += '{} = {}\n'.format(val.name, int(val))
    return enum
