1.. highlightlang:: c 2 3.. _instancemethod-objects: 4 5Instance Method Objects 6----------------------- 7 8.. index:: object: instancemethod 9 10An instance method is a wrapper for a :c:data:`PyCFunction` and the new way 11to bind a :c:data:`PyCFunction` to a class object. It replaces the former call 12``PyMethod_New(func, NULL, class)``. 13 14 15.. c:var:: PyTypeObject PyInstanceMethod_Type 16 17 This instance of :c:type:`PyTypeObject` represents the Python instance 18 method type. It is not exposed to Python programs. 19 20 21.. c:function:: int PyInstanceMethod_Check(PyObject *o) 22 23 Return true if *o* is an instance method object (has type 24 :c:data:`PyInstanceMethod_Type`). The parameter must not be *NULL*. 25 26 27.. c:function:: PyObject* PyInstanceMethod_New(PyObject *func) 28 29 Return a new instance method object, with *func* being any callable object 30 *func* is the function that will be called when the instance method is 31 called. 32 33 34.. c:function:: PyObject* PyInstanceMethod_Function(PyObject *im) 35 36 Return the function object associated with the instance method *im*. 37 38 39.. c:function:: PyObject* PyInstanceMethod_GET_FUNCTION(PyObject *im) 40 41 Macro version of :c:func:`PyInstanceMethod_Function` which avoids error checking. 42 43 44.. _method-objects: 45 46Method Objects 47-------------- 48 49.. index:: object: method 50 51Methods are bound function objects. Methods are always bound to an instance of 52a user-defined class. Unbound methods (methods bound to a class object) are 53no longer available. 54 55 56.. c:var:: PyTypeObject PyMethod_Type 57 58 .. index:: single: MethodType (in module types) 59 60 This instance of :c:type:`PyTypeObject` represents the Python method type. This 61 is exposed to Python programs as ``types.MethodType``. 62 63 64.. c:function:: int PyMethod_Check(PyObject *o) 65 66 Return true if *o* is a method object (has type :c:data:`PyMethod_Type`). The 67 parameter must not be *NULL*. 68 69 70.. c:function:: PyObject* PyMethod_New(PyObject *func, PyObject *self) 71 72 Return a new method object, with *func* being any callable object and *self* 73 the instance the method should be bound. *func* is the function that will 74 be called when the method is called. *self* must not be *NULL*. 75 76 77.. c:function:: PyObject* PyMethod_Function(PyObject *meth) 78 79 Return the function object associated with the method *meth*. 80 81 82.. c:function:: PyObject* PyMethod_GET_FUNCTION(PyObject *meth) 83 84 Macro version of :c:func:`PyMethod_Function` which avoids error checking. 85 86 87.. c:function:: PyObject* PyMethod_Self(PyObject *meth) 88 89 Return the instance associated with the method *meth*. 90 91 92.. c:function:: PyObject* PyMethod_GET_SELF(PyObject *meth) 93 94 Macro version of :c:func:`PyMethod_Self` which avoids error checking. 95 96 97.. c:function:: int PyMethod_ClearFreeList() 98 99 Clear the free list. Return the total number of freed items. 100 101