enum_tools.autoenum

A Sphinx directive for documenting Enums in Python.

Provides the autoenum directive for documenting Enums, and autoflag for documenting Flags.

It behaves much like autoclass and autofunction.

See also https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html.

Changed in version 0.4.0: Added PyEnumXRefRole and py:enum:mem.

Classes:

EnumDocumenter(*args)

Sphinx autodoc Documenter for documenting Enums.

EnumMemberDocumenter(directive, name[, indent])

Sphinx autodoc Documenter for documenting Enum members.

FlagDocumenter(*args)

Sphinx autodoc Documenter for documenting Flags.

PyEnumXRefRole([fix_parens, lowercase, …])

XRefRole for Enum/Flag members.

Functions:

setup(app)

Setup Sphinx Extension.

class EnumDocumenter(*args)[source]

Bases: ClassDocumenter

Sphinx autodoc Documenter for documenting Enums.

Methods:

can_document_member(member, membername, …)

Called to see if a member can be documented by this documenter.

document_members([all_members])

Generate reST for member documentation.

generate([more_content, real_modname, …])

Generate reST for the object given by self.name, and possibly for its members.

classmethod can_document_member(member, membername, isattr, parent)[source]

Called to see if a member can be documented by this documenter.

Parameters
Return type

bool

document_members(all_members=False)[source]

Generate reST for member documentation.

Parameters

all_members (bool) – If True, document all members, otherwise document those given by else those given by self.options.members. Default False.

generate(more_content=None, real_modname=None, check_module=False, all_members=False)[source]

Generate reST for the object given by self.name, and possibly for its members.

Parameters
  • more_content (Optional[Any]) – Additional content to include in the reST output. Default None.

  • real_modname (Optional[str]) – Module name to use to find attribute documentation. Default None.

  • check_module (bool) – If True, only generate if the object is defined in the module name it is imported from. Default False.

  • all_members (bool) – If True, document all members. Default False.

class EnumMemberDocumenter(directive, name, indent='')[source]

Bases: AttributeDocumenter

Sphinx autodoc Documenter for documenting Enum members.

Methods:

generate([more_content, real_modname, …])

Generate reST for the object given by self.name, and possibly for its members.

import_object([raiseerror])

Import the object given by self.modname and self.objpath and set it as self.object.

generate(more_content=None, real_modname=None, check_module=False, all_members=False)[source]

Generate reST for the object given by self.name, and possibly for its members.

Parameters
  • more_content (Optional[Any]) – Additional content to include in the reST output. Default None.

  • real_modname (Optional[str]) – Module name to use to find attribute documentation. Default None.

  • check_module (bool) – If True, only generate if the object is defined in the module name it is imported from. Default False.

  • all_members (bool) – If True, document all members. Default False.

import_object(raiseerror=False)[source]

Import the object given by self.modname and self.objpath and set it as self.object.

Parameters

raiseerror (bool) – Default False.

Return type

Any

Returns

True if successful, False if an error occurred.

class FlagDocumenter(*args)[source]

Bases: EnumDocumenter

Sphinx autodoc Documenter for documenting Flags.

Methods:

can_document_member(member, membername, …)

Called to see if a member can be documented by this documenter.

classmethod can_document_member(member, membername, isattr, parent)[source]

Called to see if a member can be documented by this documenter.

Parameters
Return type

bool

class PyEnumXRefRole(fix_parens=False, lowercase=False, nodeclass=None, innernodeclass=None, warn_dangling=False)[source]

Bases: PyXRefRole

XRefRole for Enum/Flag members.

New in version 0.4.0.

Methods:

process_link(env, refnode, …)

Called after parsing title and target text, and creating the reference node (given in refnode).

Called after parsing title and target text, and creating the reference node (given in refnode). This method can alter the reference node and must return a new (or the same) (title, target) tuple.

Return type

Tuple[str, str]

setup(app)[source]

Setup Sphinx Extension.

Parameters

app (Sphinx)

Return type

Dict[str, Any]