| 
									
										
										
										
											2019-05-17 11:55:34 +02:00
										 |  |  | .. highlight:: c
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | .. _instancemethod-objects:
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Instance Method Objects
 | 
					
						
							|  |  |  | -----------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .. index:: object: instancemethod
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | 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
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | ``PyMethod_New(func, NULL, class)``.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:var:: PyTypeObject PyInstanceMethod_Type
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  |    This instance of :c:type:`PyTypeObject` represents the Python instance
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  |    method type. It is not exposed to Python programs.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:function:: int PyInstanceMethod_Check(PyObject *o)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |    Return true if *o* is an instance method object (has type
 | 
					
						
							| 
									
										
										
										
											2019-10-30 12:03:20 +02:00
										 |  |  |    :c:data:`PyInstanceMethod_Type`).  The parameter must not be ``NULL``.
 | 
					
						
							| 
									
										
										
										
											2021-01-06 04:54:18 -08:00
										 |  |  |    This function always succeeds.
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:function:: PyObject* PyInstanceMethod_New(PyObject *func)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |    Return a new instance method object, with *func* being any callable object
 | 
					
						
							| 
									
										
										
										
											2011-10-19 10:58:56 +03:00
										 |  |  |    *func* is the function that will be called when the instance method is
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  |    called.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:function:: PyObject* PyInstanceMethod_Function(PyObject *im)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |    Return the function object associated with the instance method *im*.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:function:: PyObject* PyInstanceMethod_GET_FUNCTION(PyObject *im)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  |    Macro version of :c:func:`PyInstanceMethod_Function` which avoids error checking.
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .. _method-objects:
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Method Objects
 | 
					
						
							|  |  |  | --------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .. index:: object: method
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Methods are bound function objects. Methods are always bound to an instance of
 | 
					
						
							| 
									
										
										
										
											2016-04-15 02:14:19 +00:00
										 |  |  | a user-defined class. Unbound methods (methods bound to a class object) are
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | no longer available.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:var:: PyTypeObject PyMethod_Type
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |    .. index:: single: MethodType (in module types)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  |    This instance of :c:type:`PyTypeObject` represents the Python method type.  This
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  |    is exposed to Python programs as ``types.MethodType``.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:function:: int PyMethod_Check(PyObject *o)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  |    Return true if *o* is a method object (has type :c:data:`PyMethod_Type`).  The
 | 
					
						
							| 
									
										
										
										
											2021-01-06 04:54:18 -08:00
										 |  |  |    parameter must not be ``NULL``.  This function always succeeds.
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:function:: PyObject* PyMethod_New(PyObject *func, PyObject *self)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |    Return a new method object, with *func* being any callable object and *self*
 | 
					
						
							| 
									
										
										
										
											2011-10-19 10:58:56 +03:00
										 |  |  |    the instance the method should be bound. *func* is the function that will
 | 
					
						
							| 
									
										
										
										
											2019-10-30 12:03:20 +02:00
										 |  |  |    be called when the method is called. *self* must not be ``NULL``.
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:function:: PyObject* PyMethod_Function(PyObject *meth)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |    Return the function object associated with the method *meth*.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:function:: PyObject* PyMethod_GET_FUNCTION(PyObject *meth)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  |    Macro version of :c:func:`PyMethod_Function` which avoids error checking.
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:function:: PyObject* PyMethod_Self(PyObject *meth)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |    Return the instance associated with the method *meth*.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:function:: PyObject* PyMethod_GET_SELF(PyObject *meth)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  |    Macro version of :c:func:`PyMethod_Self` which avoids error checking.
 |