Commits

Kamil Kisiel committed a43f10a

Added some basic documentation

  • Participants
  • Parent commits 7d6922c

Comments (0)

Files changed (3)

covenant/annotations.py

 
 @toggled_decorator
 def constrain(func):
+    """Enforce constraints on a function defined by its annotations.
+
+    Each annotation should be a callable that takes a single parameter and
+    returns a True or False value.
+
+    """
     @wraps(func)
     def wrapped_func(*args, **kwargs):
         callargs = getcallargs(func, *args, **kwargs)

covenant/conditions.py

 
 @toggled_decorator_func
 def pre(condition):
+    """Enforce a precondition on the decorated function.
+
+    The `condition` must be a callable that receives the same keyword arguments
+    as the function it's being applied to.
+
+    """
     def _pre(func):
         @wraps(func)
         def wrapped_func(*args, **kwargs):
 
 @toggled_decorator_func
 def post(condition):
+    """Enforce a postcondition on the decorated function.
+
+    The `condition` must be a callable that receives the return value of the
+    function it's being applied to as its first parameter, and the keyword
+    arguments of the function it's applied to as its remaining parameters.
+
+    """
     def _post(func):
         @wraps(func)
         def wrapped_func(*args, **kwargs):

covenant/invariant.py

 
 @toggled_decorator_func
 def invariant(condition):
+    """Enforce a class invariant on the decorated class.
+
+    The `condition` must be a callable that takes a class instance as its
+    parameter.
+
+    The invariant will be checked once before an instance method of the class
+    is called and once after. The invariant is *not* checked multiple times
+    within a single call (eg: if the method calls another method).
+
+    """
     def _invariant(cls):
         for attr_name, attr in getmembers(cls, isfunction):
             if 'self' in getargspec(attr).args: