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