blob: 4dbe508ef95c9b7b16dc3fa36dc9978e638b0974 [file] [log] [blame]
Georg Brandlf6842722008-01-19 22:08:21 +00001.. highlightlang:: c
2
3.. _classobjects:
4
5Class and Instance Objects
6--------------------------
7
8.. index:: object: class
9
10Note that the class objects described here represent old-style classes, which
11will go away in Python 3. When creating new types for extension modules, you
12will want to work with type objects (section :ref:`typeobjects`).
13
14
Sandro Tosi98ed08f2012-01-14 16:42:02 +010015.. c:type:: PyClassObject
Georg Brandlf6842722008-01-19 22:08:21 +000016
17 The C structure of the objects used to describe built-in classes.
18
19
Sandro Tosi98ed08f2012-01-14 16:42:02 +010020.. c:var:: PyObject* PyClass_Type
Georg Brandlf6842722008-01-19 22:08:21 +000021
22 .. index:: single: ClassType (in module types)
23
24 This is the type object for class objects; it is the same object as
25 ``types.ClassType`` in the Python layer.
26
27
Sandro Tosi98ed08f2012-01-14 16:42:02 +010028.. c:function:: int PyClass_Check(PyObject *o)
Georg Brandlf6842722008-01-19 22:08:21 +000029
30 Return true if the object *o* is a class object, including instances of types
31 derived from the standard class object. Return false in all other cases.
32
33
Sandro Tosi98ed08f2012-01-14 16:42:02 +010034.. c:function:: int PyClass_IsSubclass(PyObject *klass, PyObject *base)
Georg Brandlf6842722008-01-19 22:08:21 +000035
36 Return true if *klass* is a subclass of *base*. Return false in all other cases.
37
38
39.. index:: object: instance
40
41There are very few functions specific to instance objects.
42
43
Sandro Tosi98ed08f2012-01-14 16:42:02 +010044.. c:var:: PyTypeObject PyInstance_Type
Georg Brandlf6842722008-01-19 22:08:21 +000045
46 Type object for class instances.
47
48
Sandro Tosi98ed08f2012-01-14 16:42:02 +010049.. c:function:: int PyInstance_Check(PyObject *obj)
Georg Brandlf6842722008-01-19 22:08:21 +000050
51 Return true if *obj* is an instance.
52
53
Sandro Tosi98ed08f2012-01-14 16:42:02 +010054.. c:function:: PyObject* PyInstance_New(PyObject *class, PyObject *arg, PyObject *kw)
Georg Brandlf6842722008-01-19 22:08:21 +000055
56 Create a new instance of a specific class. The parameters *arg* and *kw* are
57 used as the positional and keyword parameters to the object's constructor.
58
59
Sandro Tosi98ed08f2012-01-14 16:42:02 +010060.. c:function:: PyObject* PyInstance_NewRaw(PyObject *class, PyObject *dict)
Georg Brandlf6842722008-01-19 22:08:21 +000061
62 Create a new instance of a specific class without calling its constructor.
63 *class* is the class of new object. The *dict* parameter will be used as the
64 object's :attr:`__dict__`; if *NULL*, a new dictionary will be created for the
65 instance.