enum_tools.documentation

Core Functionality

Decorators to add docstrings to enum members from comments.

Classes:

DocumentedEnum(value)

An enum where docstrings are automatically added to members from comments starting with doc:.

Functions:

document_enum(an_enum)

Document all members of an enum by adding a comment to the end of each line that starts with doc:.

document_member(enum_member)

Document a member of an enum by adding a comment to the end of the line that starts with doc:.

enum DocumentedEnum(value)[source]

Bases: enum.Enum

An enum where docstrings are automatically added to members from comments starting with doc:.

@document_enum(an_enum)[source]

Document all members of an enum by adding a comment to the end of each line that starts with doc:.

Parameters

an_enum (EnumMeta) – An Enum subclass

Return type

EnumMeta

document_member(enum_member)[source]

Document a member of an enum by adding a comment to the end of the line that starts with doc:.

Parameters

enum_member (Enum) – A member of an Enum subclass

Utilities

Functions:

get_base_indent(base_indent, all_tokens, indent)

Determine the base level of indentation (i.e.

get_dedented_line(line)

Returns the line without indentation, and the amount of indentation.

get_tokens(line)

Returns a list ot tokens generated from the given Python code.

parse_tokens(all_tokens)

Parse the tokens representing a line of code to identify Enum members and doc: comments.

get_base_indent(base_indent, all_tokens, indent)[source]

Determine the base level of indentation (i.e. one level of indentation in from the c of class).

Parameters
  • base_indent (Optional[int]) – The current base level of indentation

  • all_tokens

  • indent (int) – The current level of indentation

Return type

Optional[int]

Returns

The base level of indentation

get_dedented_line(line)[source]

Returns the line without indentation, and the amount of indentation.

Parameters

line (str) – A line of Python source code

Return type

Tuple[int, str]

Returns

get_tokens(line)[source]

Returns a list ot tokens generated from the given Python code.

Parameters

line (str) – Line of Python code to tokenise.

Return type

List[Tuple]

parse_tokens(all_tokens)[source]

Parse the tokens representing a line of code to identify Enum members and doc: comments.

Parameters

all_tokens

Returns

A list of the Enum members’ names, and the docstring for them.