2008-01-19 18:08:21 -04:00
|
|
|
.. highlightlang:: c
|
|
|
|
|
|
|
|
.. _method-objects:
|
|
|
|
|
|
|
|
Method Objects
|
|
|
|
--------------
|
|
|
|
|
|
|
|
.. index:: object: method
|
|
|
|
|
|
|
|
There are some useful functions that are useful for working with method objects.
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:var:: PyTypeObject PyMethod_Type
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
.. index:: single: MethodType (in module types)
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
This instance of :c:type:`PyTypeObject` represents the Python method type. This
|
2008-01-19 18:08:21 -04:00
|
|
|
is exposed to Python programs as ``types.MethodType``.
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: int PyMethod_Check(PyObject *o)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
Return true if *o* is a method object (has type :c:data:`PyMethod_Type`). The
|
2008-01-19 18:08:21 -04:00
|
|
|
parameter must not be *NULL*.
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: PyObject* PyMethod_New(PyObject *func, PyObject *self, PyObject *class)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
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..
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: PyObject* PyMethod_Class(PyObject *meth)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: PyObject* PyMethod_GET_CLASS(PyObject *meth)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
Macro version of :c:func:`PyMethod_Class` which avoids error checking.
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: PyObject* PyMethod_Function(PyObject *meth)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
Return the function object associated with the method *meth*.
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: PyObject* PyMethod_GET_FUNCTION(PyObject *meth)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
Macro version of :c:func:`PyMethod_Function` which avoids error checking.
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: PyObject* PyMethod_Self(PyObject *meth)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
Return the instance associated with the method *meth* if it is bound, otherwise
|
|
|
|
return *NULL*.
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: PyObject* PyMethod_GET_SELF(PyObject *meth)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
Macro version of :c:func:`PyMethod_Self` which avoids error checking.
|
2008-02-14 08:47:33 -04:00
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: int PyMethod_ClearFreeList()
|
2008-02-14 08:47:33 -04:00
|
|
|
|
|
|
|
Clear the free list. Return the total number of freed items.
|
|
|
|
|
|
|
|
.. versionadded:: 2.6
|