method.rst 2.75 KB
Newer Older
1 2 3 4 5 6 7 8 9
.. highlightlang:: c

.. _instancemethod-objects:

Instance Method Objects
-----------------------

.. index:: object: instancemethod

10 11
An instance method is a wrapper for a :c:data:`PyCFunction` and the new way
to bind a :c:data:`PyCFunction` to a class object. It replaces the former call
12 13 14
``PyMethod_New(func, NULL, class)``.


15
.. c:var:: PyTypeObject PyInstanceMethod_Type
16

17
   This instance of :c:type:`PyTypeObject` represents the Python instance
18 19 20
   method type. It is not exposed to Python programs.


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
Ezio Melotti's avatar
Ezio Melotti committed
30
   *func* is the function that will be called when the instance method is
31 32 33
   called.


34
.. c:function:: PyObject* PyInstanceMethod_Function(PyObject *im)
35 36 37 38

   Return the function object associated with the instance method *im*.


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 45 46 47 48 49 50 51 52 53 54 55


.. _method-objects:

Method Objects
--------------

.. index:: object: method

Methods are bound function objects. Methods are always bound to an instance of
an user-defined class. Unbound methods (methods bound to a class object) are
no longer available.


56
.. c:var:: PyTypeObject PyMethod_Type
57 58 59

   .. index:: single: MethodType (in module types)

60
   This instance of :c:type:`PyTypeObject` represents the Python method type.  This
61 62 63
   is exposed to Python programs as ``types.MethodType``.


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 68 69
   parameter must not be *NULL*.


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*
Ezio Melotti's avatar
Ezio Melotti committed
73
   the instance the method should be bound. *func* is the function that will
74 75 76
   be called when the method is called. *self* must not be *NULL*.


77
.. c:function:: PyObject* PyMethod_Function(PyObject *meth)
78 79 80 81

   Return the function object associated with the method *meth*.


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 90 91

   Return the instance associated with the method *meth*.


92
.. c:function:: PyObject* PyMethod_GET_SELF(PyObject *meth)
93

94
   Macro version of :c:func:`PyMethod_Self` which avoids error checking.
Christian Heimes's avatar
Christian Heimes committed
95 96


97
.. c:function:: int PyMethod_ClearFreeList()
Christian Heimes's avatar
Christian Heimes committed
98 99 100

   Clear the free list. Return the total number of freed items.