eradiate.attrs#

attrs-based utility classes and functions.

Attributes#

eradiate.attrs.AUTO#

Sentinel to indicate when a dynamic field value is expected to be set automatically.

eradiate.attrs.AutoType(*args, **kwargs)#

Typing alias for AUTO.

Attribute docs extension#

eradiate.attrs.parse_docs(cls)[source]#

Extract attribute documentation and update class docstring with it.

This decorator will examine each attrs attribute and check its metadata for documentation content. It will then update the class’s docstring based on this content.

Parameters:

cls (type) – Class whose attributes should be processed.

Returns:

type – Updated class.

See also

documented()

Field documentation definition function.

Notes

  • Meant to be used as a class decorator.

  • Must be applied after @attr.s (or any other attrs decorator).

  • Fields must be documented using documented().

eradiate.attrs.documented(attrib, doc=None, type=None, init_type=None, default=None)[source]#

Declare an attrs field as documented.

Parameters:
  • attrib (attrs.Attribute) – attrs attribute definition to which documentation is to be attached.

  • doc (str, optional) – Docstring for the considered field. If set to None, this function does nothing.

  • type (str, optional) – Documented type for the considered field.

  • init_type (str, optional) – Documented constructor parameter for the considered field.

  • default (str, optional) – Documented default value for the considered field.

Returns:

attrs.Attributeattrib, with metadata updated with documentation contents.

See also

attrs.field(), pinttr.field(), parse_docs()

eradiate.attrs.get_doc(cls, attrib, field)[source]#

Fetch attribute documentation field. Requires field metadata to be processed with documented().

Parameters:
  • cls (type) – Class from which to get the attribute.

  • attrib (str) – Attribute from which to get the doc field.

  • field ({"doc", "type", "init_type", "default"}) – Documentation field to query.

Returns:

str – Queried documentation content.

Raises:
  • ValueError – If the requested field is missing from the target attribute’s metadata.

  • ValueError – If the requested field is unsupported.