我在python2.7中有以下代码,其中装饰器是第三方代码,不得更改:
# tasks.py
def test(val):
print val
@app.task
def add(a, b):
return a + b
#main.py:
import mypackage.tasks as tasks
for method in tasks.__dict__.values():
if hasattr(method, '_decorated') and method._decorated:
print method.name.split('.')[-1]
### here I want to get the method arguments
问题是我无法获取装饰方法的方法参数。 我已经尝试过了:
inspect.getargspec(method)
#and
tasks.test.func_code.co_varnames
它们不适用于装饰方法。 有什么想法吗?