function_prototype.py 文件源码

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

项目:proator 作者: mohit-thakur-721 项目源码 文件源码
def ovrprototype(*outer_args,**outer_kwargs):  
    """ Verify that a method is called with a valid data type value.
        The datatype of a parameter must be a list of type defined 
        in package types. 
    """
    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):
                matched = False
                for i_typ in typ:
                    if ( isinstance(var, i_typ)):
                        matched = True
                        break
                if matched == False:
                    sys.excepthook = __exceptionHandler__
                    raise Exception("Invalid Type")
            return fn(*args,**kwargs)                         
        return decorated                                          
    return decorator
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号