2.4. fancytypes.Updatable
- class Updatable(validation_and_conversion_funcs={}, params_to_be_mapped_to_core_attrs={}, skip_validation_and_conversion=False)[source]
Bases:
CheckableA type that can perform user-defined validations and conversions of a set of parameters upon construction, and that has an updatable subset of attributes.
- 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_attrsdenote the attributefancytypes.Updatable.core_attrs, which is a dict object.If
skip_validation_and_conversionis set toFalse, then for each keykeyinparams_to_be_mapped_to_core_attrs,core_attrs[key]is set tovalidation_and_conversion_funcs[key] (params_to_be_mapped_to_core_attrs).Otherwise, if
skip_validation_and_conversionis set toTrue, thencore_attrsis set toparams_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 ofparams_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
keyincore_attrs,validation_and_conversion_funcs[key](core_attrs)is expected to not raise an exception.- Type:
dict, read-only
Methods
Return the core attributes.
Update a subset of the core attributes.
Attributes
- get_core_attrs(deep_copy=True)[source]
Return the core attributes.
- Parameters:
deep_copy (bool, optional) – If
deep_copyis set toTrue, 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
- update(new_core_attr_subset_candidate={}, skip_validation_and_conversion=False)[source]
Update a subset of the core attributes.
- Parameters:
new_core_attr_subset_candidate (dict, optional) – A dict object.
skip_validation_and_conversion (bool, optional) –
Let
core_attrsandvalidation_and_conversion_funcsdenote the attributesfancytypes.Updatable.core_attrsandfancytypes.Updatable.validation_and_conversion_funcsrespectively, which are both dict objects.If
skip_validation_and_conversionis set toFalse, then for each keykeyincore_attrsthat is also innew_core_attr_subset_candidate,core_attrs[key]is set tovalidation_and_conversion_funcs[key] (new_core_attr_subset_candidate).Otherwise, if
skip_validation_and_conversionis set toTrue, then for each keykeyincore_attrsthat is also innew_core_attr_subset_candidate,core_attrs[key]is set tonew_core_attr_subset_candidate[key]. This option is desired primarily when the user wants to avoid potentially expensive copies and/or conversions of the dict values ofnew_core_attr_subset_candidate, as it is guaranteed that no copies or conversions are made in this case.