My favorites | Sign in
Project Logo
                
Show all Featured wiki pages:
AnnotationTools
Feeds:
People details
Project owners:
  ferenczi.viktor

The anntools package provides various modules to take advantage of Python 3.0's new function annotation feature. It supports validation, conversion and type checking of parameters passed to functions and their return values. It is useful for adding security checks and make your code more readable. This package is useful for Python 2.4 and up, since all functionality are provided as keyword arguments for decorators as well.

Examples and documentation

Quick example: Validation

For Python 2.4-2.6:

@validate(Unicode, n=Int)
def myfunc(n):
    return u'#'*n

For Python 3.0:

@validate
def myfunc(n:Int) -> Str:
    return '#'*n

For Python 3.0 with limits:

@validate
def myfunc(n:Int(min=1, max=10)) -> Str(maxlen=10):
    return '#'*n








Hosted by Google Code