def __func(*args, **kwargs): for i, param in enumerate(args): req = spec.get(func_args[i], _marker) if req is not _marker and sys.get_type(param) is not req: raise TypeError("%s has to be %r" % (func_args[i], req)) for name, param in kwargs.iteritems(): if name in spec and sys.get_type(param) is not spec[name]: raise TypeError("%s has to be %r" % (name, spec[name])) return function(*args, **kwargs)
def __func(*args, **kwargs): for i, param in enumerate(args): req = spec.get(func_args[i], _marker) if req is not _marker and sys.get_type(param) is not req: raise TypeError( "%s has to be %r" % (func_args[i], req) ) for name, param in kwargs.iteritems(): if name in spec and sys.get_type(param) is not spec[name]: raise TypeError("%s has to be %r" % (name, spec[name])) return function(*args, **kwargs)
def __decorator(function): if sys.get_type(function) is not FunctionType: raise TypeError("Incorrect argument") func_args = getargs(function.__code__)[0] len_args = len(func_args) - 1 def __func(*args, **kwargs): for i, param in enumerate(args): req = spec.get(func_args[i], _marker) if req is not _marker and sys.get_type(param) is not req: raise TypeError("%s has to be %r" % (func_args[i], req)) for name, param in kwargs.iteritems(): if name in spec and sys.get_type(param) is not spec[name]: raise TypeError("%s has to be %r" % (name, spec[name])) return function(*args, **kwargs) __func.__name__ = function.__name__ __func.__doc__ = function.__doc__ return __func
def __decorator(function): if sys.get_type(function) is not FunctionType: raise TypeError("Incorrect argument") func_args = getargs(function.__code__)[0] len_args = len(func_args) - 1 def __func(*args, **kwargs): for i, param in enumerate(args): req = spec.get(func_args[i], _marker) if req is not _marker and sys.get_type(param) is not req: raise TypeError( "%s has to be %r" % (func_args[i], req) ) for name, param in kwargs.iteritems(): if name in spec and sys.get_type(param) is not spec[name]: raise TypeError("%s has to be %r" % (name, spec[name])) return function(*args, **kwargs) __func.__name__ = function.__name__ __func.__doc__ = function.__doc__ return __func