constraints provides several facilities:
The abstract class generator Constraints
Constraint classes generated by Constraints can validate instance attribute values when used as descriptors. The condition classes provide context managers, and both Precondition and Postcondition can be used as function decorators.
Base class for design by contract style conditions.
Constraint base class. Constraints are usable as descriptors.
Metaclass which provides constraint verification for objects. Constraints are specified as arguments to the __new__ method. Constraints can be either no argument callables or Symbol expressions.
isinstance(obj, ConstraintsInstance) will return True iff obj satisfies all constraints.
Constraint container that verifies an invariant condition. Usable as a context manager.
Constraint container that verifies a postcondition. Usable as a decorator or context manager.
Note
The decorator constrains the return value of the decorated function. It ignores the callable and name attributes of the condition if they are present.
Constraint container that verifies a precondition. Usable as a decorator or context manager.
Note
You must specify a string argument name for the precondition or the decorator will not function properly.