def prototype(*outer_args,**outer_kwargs):
""" Verify that a method is called with a valid data type value.
The datatype of a parameter must be a one of the type
defined in types package.
"""
def decorator(fn):
def decorated(*args,**kwargs):
#do_something(*outer_args,**outer_kwargs)
if len(outer_args)!=len(args):
sys.excepthook = __exceptionHandler__
raise Exception("Invalid Number of "
"arguments in function call")
for [typ, var] in zip(outer_args, args):
if ( isinstance(var, typ)):
pass
else:
sys.excepthook = __exceptionHandler__
raise Exception("Invalid Type")
return fn(*args,**kwargs)
return decorated
return decorator
评论列表
文章目录