cpython/Doc/c-api/method.rst

96 lines
2.7 KiB
ReStructuredText
Raw Normal View History

.. highlight:: c
2008-01-20 05:30:57 -04:00
.. _instancemethod-objects:
Instance Method Objects
-----------------------
.. index:: pair: object; instancemethod
2008-01-20 05:30:57 -04: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)``.
.. c:var:: PyTypeObject PyInstanceMethod_Type
2008-01-20 05:30:57 -04: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.
.. 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
:c:data:`PyInstanceMethod_Type`). The parameter must not be ``NULL``.
This function always succeeds.
2008-01-20 05:30:57 -04:00
.. c:function:: PyObject* PyInstanceMethod_New(PyObject *func)
2008-01-20 05:30:57 -04: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.
.. 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*.
.. c:function:: PyObject* PyInstanceMethod_GET_FUNCTION(PyObject *im)
2008-01-20 05:30:57 -04:00
Macro version of :c:func:`PyInstanceMethod_Function` which avoids error checking.
2008-01-20 05:30:57 -04:00
.. _method-objects:
Method Objects
--------------
.. 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
a user-defined class. Unbound methods (methods bound to a class object) are
2008-01-20 05:30:57 -04:00
no longer available.
.. c:var:: PyTypeObject PyMethod_Type
2008-01-20 05:30:57 -04:00
.. index:: single: MethodType (in module types)
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``.
.. c:function:: int PyMethod_Check(PyObject *o)
2008-01-20 05:30:57 -04:00
Return true if *o* is a method object (has type :c:data:`PyMethod_Type`). The
parameter must not be ``NULL``. This function always succeeds.
2008-01-20 05:30:57 -04: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
be called when the method is called. *self* must not be ``NULL``.
2008-01-20 05:30:57 -04: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*.
.. c:function:: PyObject* PyMethod_GET_FUNCTION(PyObject *meth)
2008-01-20 05:30:57 -04:00
Macro version of :c:func:`PyMethod_Function` which avoids error checking.
2008-01-20 05:30:57 -04:00
.. c:function:: PyObject* PyMethod_Self(PyObject *meth)
2008-01-20 05:30:57 -04:00
Return the instance associated with the method *meth*.
.. c:function:: PyObject* PyMethod_GET_SELF(PyObject *meth)
2008-01-20 05:30:57 -04:00
Macro version of :c:func:`PyMethod_Self` which avoids error checking.