blob: 71ddedaf78a797269b50f4f78295825f269a59c6 [file] [log] [blame]
Georg Brandlf6842722008-01-19 22:08:21 +00001.. highlightlang:: c
2
3.. _method-objects:
4
5Method Objects
6--------------
7
8.. index:: object: method
9
10There are some useful functions that are useful for working with method objects.
11
12
Sandro Tosi98ed08f2012-01-14 16:42:02 +010013.. c:var:: PyTypeObject PyMethod_Type
Georg Brandlf6842722008-01-19 22:08:21 +000014
15 .. index:: single: MethodType (in module types)
16
Sandro Tosi98ed08f2012-01-14 16:42:02 +010017 This instance of :c:type:`PyTypeObject` represents the Python method type. This
Georg Brandlf6842722008-01-19 22:08:21 +000018 is exposed to Python programs as ``types.MethodType``.
19
20
Sandro Tosi98ed08f2012-01-14 16:42:02 +010021.. c:function:: int PyMethod_Check(PyObject *o)
Georg Brandlf6842722008-01-19 22:08:21 +000022
Sandro Tosi98ed08f2012-01-14 16:42:02 +010023 Return true if *o* is a method object (has type :c:data:`PyMethod_Type`). The
Georg Brandlf6842722008-01-19 22:08:21 +000024 parameter must not be *NULL*.
25
26
Sandro Tosi98ed08f2012-01-14 16:42:02 +010027.. c:function:: PyObject* PyMethod_New(PyObject *func, PyObject *self, PyObject *class)
Georg Brandlf6842722008-01-19 22:08:21 +000028
29 Return a new method object, with *func* being any callable object; this is the
30 function that will be called when the method is called. If this method should
31 be bound to an instance, *self* should be the instance and *class* should be the
32 class of *self*, otherwise *self* should be *NULL* and *class* should be the
33 class which provides the unbound method..
34
35
Sandro Tosi98ed08f2012-01-14 16:42:02 +010036.. c:function:: PyObject* PyMethod_Class(PyObject *meth)
Georg Brandlf6842722008-01-19 22:08:21 +000037
38 Return the class object from which the method *meth* was created; if this was
39 created from an instance, it will be the class of the instance.
40
41
Sandro Tosi98ed08f2012-01-14 16:42:02 +010042.. c:function:: PyObject* PyMethod_GET_CLASS(PyObject *meth)
Georg Brandlf6842722008-01-19 22:08:21 +000043
Sandro Tosi98ed08f2012-01-14 16:42:02 +010044 Macro version of :c:func:`PyMethod_Class` which avoids error checking.
Georg Brandlf6842722008-01-19 22:08:21 +000045
46
Sandro Tosi98ed08f2012-01-14 16:42:02 +010047.. c:function:: PyObject* PyMethod_Function(PyObject *meth)
Georg Brandlf6842722008-01-19 22:08:21 +000048
49 Return the function object associated with the method *meth*.
50
51
Sandro Tosi98ed08f2012-01-14 16:42:02 +010052.. c:function:: PyObject* PyMethod_GET_FUNCTION(PyObject *meth)
Georg Brandlf6842722008-01-19 22:08:21 +000053
Sandro Tosi98ed08f2012-01-14 16:42:02 +010054 Macro version of :c:func:`PyMethod_Function` which avoids error checking.
Georg Brandlf6842722008-01-19 22:08:21 +000055
56
Sandro Tosi98ed08f2012-01-14 16:42:02 +010057.. c:function:: PyObject* PyMethod_Self(PyObject *meth)
Georg Brandlf6842722008-01-19 22:08:21 +000058
59 Return the instance associated with the method *meth* if it is bound, otherwise
60 return *NULL*.
61
62
Sandro Tosi98ed08f2012-01-14 16:42:02 +010063.. c:function:: PyObject* PyMethod_GET_SELF(PyObject *meth)
Georg Brandlf6842722008-01-19 22:08:21 +000064
Sandro Tosi98ed08f2012-01-14 16:42:02 +010065 Macro version of :c:func:`PyMethod_Self` which avoids error checking.
Christian Heimes3b718a72008-02-14 12:47:33 +000066
67
Sandro Tosi98ed08f2012-01-14 16:42:02 +010068.. c:function:: int PyMethod_ClearFreeList()
Christian Heimes3b718a72008-02-14 12:47:33 +000069
70 Clear the free list. Return the total number of freed items.
71
72 .. versionadded:: 2.6