Can't get argspec for Python callables?

Viewed 4209

I'm playing with Python callable. Basically you can define a python class and implement __call__ method to make the instance of this class callable. e.g.,

class AwesomeFunction(object):
    def __call__(self, a, b):
        return a+b

Module inspect has a function getargspec, which gives you the argument specification of a function. However, it seems I cannot use it on a callable object:

fn = AwesomeFunction()
import inspect
inspect.getargspec(fn)

Unfortunately, I got a TypeError:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/inspect.py", line 803, in getargspec
    raise TypeError('arg is not a Python function')
TypeError: arg is not a Python function

I think it's quite unfortunate that you can't treat any callable object as function, unless I'm doing something wrong here?

3 Answers
Related