【发布时间】:2018-02-24 23:45:49
【问题描述】:
def args_typecheck(func):
def wrapper(type):
def inner(*args):
if not all(map(lambda x: isinstance(x, type), args)):
raise TypeError
return func(*args)
return inner
return wrapper
@args_typecheck(str)
def seq(*args):
return reduce(operator.eq, args)
我尝试使用装饰器检查输入参数类型。但它不起作用。
错误:
if not all(map(lambda x: isinstance(x, type), args)): E TypeError: isinstance() arg 2 必须是类型或类型的元组
【问题讨论】: