Python 标准库是否有编写接受参数的装饰器的快捷方式?
例如,如果我想编写一个装饰器,例如with_timeout(timeout):
@with_timeout(10.0)
def cook_eggs(eggs):
    while not eggs.are_done():
        eggs.cook()
我必须写一些类似的东西:
def with_timeout(timeout):
    _func = [None]
    def with_timeout_helper(*args, **kwargs):
        with Timeout(timeout):
            return _func[0](*args, **kwargs)
    def with_timeout_return(f):
        return functools.wraps(f)(with_timeout_helper)
    return with_timeout_return
但这非常冗长。是否有一种捷径可以让接受参数的装饰器更容易编写?
注意:我意识到也可以使用三个嵌套函数来实现带参数的装饰器……但这也有点不太理想。
例如,可能类似于@decorator_with_arguments函数:
@decorator_with_arguments
def timeout(f, timeout):
    @functools.wraps(f)
    def timeout_helper(*args, **kwargs):
        with Timeout(timeout):
            return f(*args, **kwargs)
    return timeout_helper