最佳答案
假设我有以下几点:
def with_connection(f):
def decorated(*args, **kwargs):
f(get_connection(...), *args, **kwargs)
return decorated
@with_connection
def spam(connection):
# Do something
我想要测试 spam函数,而不必经历设置连接的麻烦(或者装饰器正在做的任何事情)。
给定 spam,我如何从它去掉装饰符并得到底层的“未装饰”函数?