2.1. fancytypes.Checkable

class Checkable(validation_and_conversion_funcs={}, params_to_be_mapped_to_core_attrs={}, skip_validation_and_conversion=False)[source]

Bases: object

A type that can perform user-defined validations and conversions of a set of parameters upon construction.

Parameters:
  • validation_and_conversion_funcs (dict, optional) – A dict object of callable objects.

  • params_to_be_mapped_to_core_attrs (dict, optional) – A dict object that has a key set that is any subset of that of validation_and_conversion_funcs.

  • skip_validation_and_conversion (bool, optional) –

    Let core_attrs denote the attribute fancytypes.Checkable.core_attrs, which is a dict object.

    If skip_validation_and_conversion is set to False, then for each key key in params_to_be_mapped_to_core_attrs, core_attrs[key] is set to validation_and_conversion_funcs[key] (params_to_be_mapped_to_core_attrs).

    Otherwise, if skip_validation_and_conversion is set to True, then core_attrs is set to params_to_be_mapped_to_core_attrs. This option is desired primarily when the user wants to avoid potentially expensive copies and/or conversions of the dict values of params_to_be_mapped_to_core_attrs, as it is guaranteed that no copies or conversions are made in this case.

validation_and_conversion_funcs

Same as the constructor parameter of the same name.

Type:

dict, read-only

core_attrs

The “core attributes”, represented as a dict object. For each dict key key in core_attrs, validation_and_conversion_funcs[key](core_attrs) is expected to not raise an exception.

Type:

dict, read-only

Methods

get_core_attrs

Return the core attributes.

Attributes

get_core_attrs(deep_copy=True)[source]

Return the core attributes.

Parameters:

deep_copy (bool, optional) – If deep_copy is set to True, then a deep copy of the original dict representation of the core attributes are returned. Otherwise, a reference to the dict representation is returned.

Returns:

core_attrs – A dict representation of the core attributes: each dict key is a str representing the name of a core attribute, and the corresponding dict value is the object to which said core attribute is set.

Return type:

dict