【发布时间】:2020-01-06 12:39:03
【问题描述】:
我希望 numba 成为一个可选依赖项,这样如果安装它就快,否则就慢。所以当没有安装 numba 时,我希望 @njit 成为一个什么都不做的虚拟装饰器。
如果我关注these directions 并使用:
def njit(func):
return func
然后,当装饰器被称为 @njit(cache=True, nogil=True) 时,我收到以下错误:
TypeError: njit() got an unexpected keyword argument 'cache'
如果我尝试捕获 args 并使用忽略它们
def njit(func, *args, **kwargs):
return func
然后我得到:
missing 1 required positional argument: 'func'
我如何制作一个什么都不做并忽略 kwargs 的虚拟装饰器?
【问题讨论】:
标签: python decorator python-decorators numba