[2] | 1 | .. highlightlang:: c
|
---|
| 2 |
|
---|
| 3 | .. _classobjects:
|
---|
| 4 |
|
---|
| 5 | Class and Instance Objects
|
---|
| 6 | --------------------------
|
---|
| 7 |
|
---|
| 8 | .. index:: object: class
|
---|
| 9 |
|
---|
| 10 | Note that the class objects described here represent old-style classes, which
|
---|
| 11 | will go away in Python 3. When creating new types for extension modules, you
|
---|
| 12 | will want to work with type objects (section :ref:`typeobjects`).
|
---|
| 13 |
|
---|
| 14 |
|
---|
[391] | 15 | .. c:type:: PyClassObject
|
---|
[2] | 16 |
|
---|
| 17 | The C structure of the objects used to describe built-in classes.
|
---|
| 18 |
|
---|
| 19 |
|
---|
[391] | 20 | .. c:var:: PyObject* PyClass_Type
|
---|
[2] | 21 |
|
---|
| 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 |
|
---|
[391] | 28 | .. c:function:: int PyClass_Check(PyObject *o)
|
---|
[2] | 29 |
|
---|
| 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 |
|
---|
[391] | 34 | .. c:function:: int PyClass_IsSubclass(PyObject *klass, PyObject *base)
|
---|
[2] | 35 |
|
---|
| 36 | Return true if *klass* is a subclass of *base*. Return false in all other cases.
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | .. index:: object: instance
|
---|
| 40 |
|
---|
| 41 | There are very few functions specific to instance objects.
|
---|
| 42 |
|
---|
| 43 |
|
---|
[391] | 44 | .. c:var:: PyTypeObject PyInstance_Type
|
---|
[2] | 45 |
|
---|
| 46 | Type object for class instances.
|
---|
| 47 |
|
---|
| 48 |
|
---|
[391] | 49 | .. c:function:: int PyInstance_Check(PyObject *obj)
|
---|
[2] | 50 |
|
---|
| 51 | Return true if *obj* is an instance.
|
---|
| 52 |
|
---|
| 53 |
|
---|
[391] | 54 | .. c:function:: PyObject* PyInstance_New(PyObject *class, PyObject *arg, PyObject *kw)
|
---|
[2] | 55 |
|
---|
| 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 |
|
---|
[391] | 60 | .. c:function:: PyObject* PyInstance_NewRaw(PyObject *class, PyObject *dict)
|
---|
[2] | 61 |
|
---|
| 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.
|
---|