Skip to main content

backend.config

Creates the spock config interface that wraps attr

_base_attr#

def _base_attr(cls, kw_only, make_init, dynamic)

Map type hints to katras

Connector function that maps type hinting style to the defined katra style which uses the more strict attr.ib() definition

Handles dynamic decorators which allows for inheritance of non @spock decorated classes

Arguments:

  • cls - basic class def
  • dynamic - allows inherited classes to not be @spock decorated

Returns:

  • cls - base spock classes derived from the MRO
  • attrs_dict - the current dictionary of attr.attribute values
  • merged_annotations - dictionary of type annotations

_process_class#

def _process_class(cls, kw_only: bool, make_init: bool, dynamic: bool)

Process a given class

Arguments:

  • cls - basic class definition
  • kw_only - set kwarg only
  • make_init - make an init function
  • dynamic - allows inherited classes to not be @spock decorated

Returns:

cls with attrs dunder methods added

spock_attr#

def spock_attr(maybe_cls=None, kw_only=True, make_init=True, dynamic=False)

Map type hints to katras

Connector function that maps type hinting style to the defined katra style which uses the more strict attr.ib() definition -- this allows us to attach the correct validators for types before the attrs class is built

Arguments:

  • maybe_cls - maybe a basic class def maybe None depending on call type
  • kw_only - Make all attributes keyword-only
  • make_init - bool, define a init() method
  • dynamic - allows inherited classes to not be @spock decorated -- will automatically cast parent classes to a spock class by traversing the MRO

Returns:

  • cls - attrs class that is frozen and kw only