如何检索装饰的python方法的方法参数

时间:2015-12-25 00:54:51

标签: python-2.7

我在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

它们不适用于装饰方法。 有什么想法吗?

0 个答案:

没有答案
相关问题