2019-05-17 06:55:34 -03:00
|
|
|
.. highlight:: c
|
2008-01-20 05:30:57 -04:00
|
|
|
|
|
|
|
.. _instancemethod-objects:
|
|
|
|
|
|
|
|
Instance Method Objects
|
|
|
|
-----------------------
|
|
|
|
|
2023-05-04 07:04:41 -03:00
|
|
|
.. index:: pair: object; instancemethod
|
2008-01-20 05:30:57 -04:00
|
|
|
|
2023-07-23 07:27:05 -03:00
|
|
|
An instance method is a wrapper for a :c:type:`PyCFunction` and the new way
|
|
|
|
to bind a :c:type:`PyCFunction` to a class object. It replaces the former call
|
2008-01-20 05:30:57 -04:00
|
|
|
``PyMethod_New(func, NULL, class)``.
|
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:var:: PyTypeObject PyInstanceMethod_Type
|
2008-01-20 05:30:57 -04:00
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
This instance of :c:type:`PyTypeObject` represents the Python instance
|
2008-01-20 05:30:57 -04:00
|
|
|
method type. It is not exposed to Python programs.
|
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: int PyInstanceMethod_Check(PyObject *o)
|
2008-01-20 05:30:57 -04:00
|
|
|
|
|
|
|
Return true if *o* is an instance method object (has type
|
2019-10-30 07:03:20 -03:00
|
|
|
:c:data:`PyInstanceMethod_Type`). The parameter must not be ``NULL``.
|
2021-01-06 07:38:26 -04:00
|
|
|
This function always succeeds.
|
2008-01-20 05:30:57 -04:00
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: PyObject* PyInstanceMethod_New(PyObject *func)
|
2008-01-20 05:30:57 -04:00
|
|
|
|
2022-04-02 16:31:05 -03:00
|
|
|
Return a new instance method object, with *func* being any callable object.
|
2011-10-19 04:58:56 -03:00
|
|
|
*func* is the function that will be called when the instance method is
|
2008-01-20 05:30:57 -04:00
|
|
|
called.
|
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: PyObject* PyInstanceMethod_Function(PyObject *im)
|
2008-01-20 05:30:57 -04:00
|
|
|
|
|
|
|
Return the function object associated with the instance method *im*.
|
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: PyObject* PyInstanceMethod_GET_FUNCTION(PyObject *im)
|
2008-01-20 05:30:57 -04:00
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
Macro version of :c:func:`PyInstanceMethod_Function` which avoids error checking.
|
2008-01-20 05:30:57 -04:00
|
|
|
|
|
|
|
|
|
|
|
.. _method-objects:
|
|
|
|
|
|
|
|
Method Objects
|
|
|
|
--------------
|
|
|
|
|
2023-05-04 07:04:41 -03:00
|
|
|
.. index:: pair: object; method
|
2008-01-20 05:30:57 -04:00
|
|
|
|
|
|
|
Methods are bound function objects. Methods are always bound to an instance of
|
2016-04-14 23:14:19 -03:00
|
|
|
a user-defined class. Unbound methods (methods bound to a class object) are
|
2008-01-20 05:30:57 -04:00
|
|
|
no longer available.
|
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:var:: PyTypeObject PyMethod_Type
|
2008-01-20 05:30:57 -04:00
|
|
|
|
|
|
|
.. index:: single: MethodType (in module types)
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
This instance of :c:type:`PyTypeObject` represents the Python method type. This
|
2008-01-20 05:30:57 -04:00
|
|
|
is exposed to Python programs as ``types.MethodType``.
|
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: int PyMethod_Check(PyObject *o)
|
2008-01-20 05:30:57 -04:00
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
Return true if *o* is a method object (has type :c:data:`PyMethod_Type`). The
|
2021-01-06 07:38:26 -04:00
|
|
|
parameter must not be ``NULL``. This function always succeeds.
|
2008-01-20 05:30:57 -04:00
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: PyObject* PyMethod_New(PyObject *func, PyObject *self)
|
2008-01-20 05:30:57 -04:00
|
|
|
|
|
|
|
Return a new method object, with *func* being any callable object and *self*
|
2011-10-19 04:58:56 -03:00
|
|
|
the instance the method should be bound. *func* is the function that will
|
2019-10-30 07:03:20 -03:00
|
|
|
be called when the method is called. *self* must not be ``NULL``.
|
2008-01-20 05:30:57 -04:00
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: PyObject* PyMethod_Function(PyObject *meth)
|
2008-01-20 05:30:57 -04:00
|
|
|
|
|
|
|
Return the function object associated with the method *meth*.
|
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: PyObject* PyMethod_GET_FUNCTION(PyObject *meth)
|
2008-01-20 05:30:57 -04:00
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
Macro version of :c:func:`PyMethod_Function` which avoids error checking.
|
2008-01-20 05:30:57 -04:00
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: PyObject* PyMethod_Self(PyObject *meth)
|
2008-01-20 05:30:57 -04:00
|
|
|
|
|
|
|
Return the instance associated with the method *meth*.
|
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: PyObject* PyMethod_GET_SELF(PyObject *meth)
|
2008-01-20 05:30:57 -04:00
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
Macro version of :c:func:`PyMethod_Self` which avoids error checking.
|