function_prototype.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:proator 作者: mohit-thakur-721 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号