background: inadvertently wanting to figure out the implementation of staticmethod
, I thought that it could be implemented with a class with _ _ get__
, but it was not clear how the original version of cpython was implemented. I was a little curious that grep took a look at the source code and found that
funcobject.h
.
/* The classmethod and staticmethod types lives here, too */
PyAPI_DATA(PyTypeObject) PyClassMethod_Type;
PyAPI_DATA(PyTypeObject) PyStaticMethod_Type;
PyAPI_FUNC(PyObject *) PyClassMethod_New(PyObject *);
PyAPI_FUNC(PyObject *) PyStaticMethod_New(PyObject *);
but there is only a function header, which is useless, and it is broken here. So he came up to ask for advice:
how to find the specific implementation of the relevant python functions is more reliable? (reliable means "I"m sure you can find it this way, and there won"t be a better way to find it.")
or, when I want to figure out how a function works, are there any general routines to follow?