How to strip decorators from a function in Python
问题 Let's say I have the following: def with_connection(f): def decorated(*args, **kwargs): f(get_connection(...), *args, **kwargs) return decorated @with_connection def spam(connection): # Do something I want to test the spam function without going through the hassle of setting up a connection (or whatever the decorator is doing). Given spam , how do I strip the decorator from it and get the underlying "undecorated" function? 回答1: In the general case, you can't, because @with_connection def spam