simplebench.enums.decorators module🔗

Decorators for enums.

simplebench.enums.decorators.enum_docstrings(
enum: type[E],
) type[E][source]🔗

Attach docstrings to enum members.

Docstrings are string literals that appear directly below the enum member assignment expression within triple-quotes.

This decorator parses the source code of the enum class to find docstrings for each member and attaches them to the respective enum members.

This allows for more detailed documentation of enum members and in tools that can extract and display these docstrings.

This code is adapted from: https://stackoverflow.com/questions/19330460/how-do-i-put-docstrings-on-enums

Example usage of enum_docstrings decorator🔗
1@enum_docstrings
2class SomeEnum(Enum):
3    '''Docstring for the SomeEnum enum'''
4
5    foo_member = "foo_value"
6    '''Docstring for the foo_member enum member'''
7
8SomeEnum.foo_member.__doc__  # 'Docstring for the foo_member enum member'
Parameters:

enum – The enum class to process.

Returns:

The same enum class with member docstrings attached.