jmquintana79
9/24/2017 - 9:42 AM

decorator check arguments

Decorator to validate argument types.

# source: https://pypi.python.org/pypi/accepts/0.0.2
# install: pip install accepts
# example:
from accepts import accepts
@accepts(int)
def inc(value):
  return value+1

# single type
inc(1) # ok
inc(1.5) # exception: TypeError: ....

# multiple types
@accepts((int,float))

# None
@accepts((int,float,None))