2008-01-19 18:08:21 -04:00
|
|
|
.. highlightlang:: c
|
|
|
|
|
|
|
|
.. _classobjects:
|
|
|
|
|
|
|
|
Class and Instance Objects
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
.. index:: object: class
|
|
|
|
|
|
|
|
Note that the class objects described here represent old-style classes, which
|
|
|
|
will go away in Python 3. When creating new types for extension modules, you
|
|
|
|
will want to work with type objects (section :ref:`typeobjects`).
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:type:: PyClassObject
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
The C structure of the objects used to describe built-in classes.
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:var:: PyObject* PyClass_Type
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
.. index:: single: ClassType (in module types)
|
|
|
|
|
|
|
|
This is the type object for class objects; it is the same object as
|
|
|
|
``types.ClassType`` in the Python layer.
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: int PyClass_Check(PyObject *o)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
Return true if the object *o* is a class object, including instances of types
|
|
|
|
derived from the standard class object. Return false in all other cases.
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: int PyClass_IsSubclass(PyObject *klass, PyObject *base)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
Return true if *klass* is a subclass of *base*. Return false in all other cases.
|
|
|
|
|
|
|
|
|
|
|
|
.. index:: object: instance
|
|
|
|
|
|
|
|
There are very few functions specific to instance objects.
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:var:: PyTypeObject PyInstance_Type
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
Type object for class instances.
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: int PyInstance_Check(PyObject *obj)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
Return true if *obj* is an instance.
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: PyObject* PyInstance_New(PyObject *class, PyObject *arg, PyObject *kw)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
Create a new instance of a specific class. The parameters *arg* and *kw* are
|
|
|
|
used as the positional and keyword parameters to the object's constructor.
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: PyObject* PyInstance_NewRaw(PyObject *class, PyObject *dict)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
Create a new instance of a specific class without calling its constructor.
|
|
|
|
*class* is the class of new object. The *dict* parameter will be used as the
|
|
|
|
object's :attr:`__dict__`; if *NULL*, a new dictionary will be created for the
|
|
|
|
instance.
|