ConstrainedValueDict#
ConstrainedValueDict wraps a standard dictionary and enforces constraints on its contents.
- class valguard.constrained_dict.ConstrainedValueDict(constraint=AnyConstraint, data=None)[source]#
Bases:
MutableMapping,GenericA dictionary that stores validated Value instances.
Each value inserted must satisfy the provided Constraint instance, which is responsible for checking both type and content validity.
A mismatch between value_type and constraint may not be detected until the first value is inserted and validated.
- Parameters:
constraint (
Constraint) – The constraint that governs type and value validity.data (
Mapping[TypeVar(K),TypeVar(V, bound=TypedValue[Any])] |None) – An optional initial mapping of key-value pairs to populate the dictionary.
- Raises:
TypeError – If data is not a valid mapping or iterable of key-value pairs.
ValueError – If data contains non-pair elements.
ValidationError – If any value fails validation by the constraint.
ConfigurationError – If the constraint is misconfigured or invalid.
- ANY_CONSTRAINT = AnyConstraint#
- property constraint: Constraint#