This document is for an old version of Python that is no longer supported. You should upgrade and read the Python 当前稳定版本的文档.

# 方法对象

There are some useful functions that are useful for working with method objects.

PyTypeObject `PyMethod_Type`

  这个 `PyTypeObject` 实例代表 Python 方法类型。 它作为 `types.MethodType` 向 Python 程序公开。

int `PyMethod_Check`(PyObject *o)

  Return true if o is a method object (has type `PyMethod_Type`). The parameter must not be NULL.

PyObject* `PyMethod_New`(PyObject *func, PyObject *self, PyObject *class)
  Return value: New reference.

  Return a new method object, with func being any callable object; this is the function that will be called when the method is called. If this method should be bound to an instance, self should be the instance and class should be the class of self, otherwise self should be NULL and class should be the class which provides the unbound method..

PyObject* `PyMethod_Class`(PyObject *meth)
  Return value: Borrowed reference.

  Return the class object from which the method meth was created; if this was created from an instance, it will be the class of the instance.

PyObject* `PyMethod_GET_CLASS`(PyObject *meth)
  Return value: Borrowed reference.

  Macro version of `PyMethod_Class()` which avoids error checking.

PyObject* `PyMethod_Function`(PyObject *meth)
  Return value: Borrowed reference.

  返回关联到方法 meth 的函数对象。

PyObject* `PyMethod_GET_FUNCTION`(PyObject *meth)
  Return value: Borrowed reference.

  宏版本的 `PyMethod_Function()`，略去了错误检测。

PyObject* `PyMethod_Self`(PyObject *meth)
  Return value: Borrowed reference.

  Return the instance associated with the method meth if it is bound, otherwise return NULL.

PyObject* `PyMethod_GET_SELF`(PyObject *meth)
  Return value: Borrowed reference.

  宏版本的 `PyMethod_Self()`，省略了错误检测。

int `PyMethod_ClearFreeList`()

  清空释放列表。 返回所释放的条目数。

  2.6 新版功能.