Search code examples
pythonpython-2.6cpython

How to find out what function the Python interpreter is calling from callable PyObject?


I'm trying to trace through the Python source code where a certain function is actually called and how to get its name.

In abstract.c:

PyObject *
PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw)
{
    ternaryfunc call;
    if((call = func->ob_type->tp_name) != NULL){ 
        PyObject *result;
        ...
        result = (*call)(func, arg, kw); //How do I find out what is being called here?
        ...
    }
    ...
}

At the line with my comment, how can I get the name of what is being called? I'm able to get the object type through (char *)func->ob_type->tp_name, but I want to know the name of the function being called. (args would be nice, too)

Note: I'm working with Python 2.6.


Solution

  • The __name__ attribute of the function object should contain the name. The arguments are in arg as a tuple and kw as a dict.