天空小小岛,情挑四十,婚礼车
下面是python ddt模块的一段源码,请教下idata中的装饰器wrapper如何继承原函数名?
def data(*values): """ Method decorator to add to your test methods. Should be added to methods of instances of ``unittest.TestCase``. """ return idata(values) def idata(iterable): """ Method decorator to add to your test methods. Should be added to methods of instances of ``unittest.TestCase``. """ def wrapper(func): setattr(func, DATA_ATTR, iterable) return func return wrapper #返回的函数名为wrapper,与func传入不一致
按一般写法,wrapper之前应该还有def decorator(func),然后通过@wraps(func)保留原函数名,可是文中参数func直接在wrapper中,该如何处理呢?
已尝试直接添加@wraps(func)会提示func未定义,改写为一般形态decorator,似乎函数功能又偏离了预期,求教
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Python 实现将numpy中的nan和inf,nan替换成对应的均值
python爬虫把url链接编码成gbk2312格式过程解析
网友评论