pydoit_nb.attrs_helpers#
Tools for helping with attrs, particularly validators
TODO: move this into its own package and check with attrs developers if they want something like this in their package
AttributeInitialisationError#
- class AttributeInitialisationError(instance, attribute, value)[source]#
Bases:
ValueErrorRaised when there is an issue while initialising an
attr.Attribute
add_attrs_context#
- add_attrs_context(original)[source]#
Decorate function with a
try...exceptto add theattrscontextThis means that the information about what attribute was being set and what value it was passed is also shown to the user
- Parameters:
original – Function to decorate
- Returns:
Decorated function
Notes
Only works with Python 3.11 and above. For other Python versions, the raw error is simply shown instead
make_attrs_validator_compatible_single_input#
- make_attrs_validator_compatible_single_input(func_to_wrap)[source]#
Create a function that is compatible with validation via
attrs.field()This assumes that the function you’re wrapping only takes a single input.
- Parameters:
func_to_wrap – Function to wrap
- Returns:
Wrapped function, which can be used as a validator with
attrs.field()