Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 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 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 15 | .. c:type:: PyClassObject |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 16 | |
| 17 | The C structure of the objects used to describe built-in classes. |
| 18 | |
| 19 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 20 | .. c:var:: PyObject* PyClass_Type |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 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 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 28 | .. c:function:: int PyClass_Check(PyObject *o) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 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 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 34 | .. c:function:: int PyClass_IsSubclass(PyObject *klass, PyObject *base) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 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 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 44 | .. c:var:: PyTypeObject PyInstance_Type |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 45 | |
| 46 | Type object for class instances. |
| 47 | |
| 48 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 49 | .. c:function:: int PyInstance_Check(PyObject *obj) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 50 | |
| 51 | Return true if *obj* is an instance. |
| 52 | |
| 53 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 54 | .. c:function:: PyObject* PyInstance_New(PyObject *class, PyObject *arg, PyObject *kw) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 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 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 60 | .. c:function:: PyObject* PyInstance_NewRaw(PyObject *class, PyObject *dict) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 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 |
Martin Panter | d51b0f2 | 2016-06-18 03:57:31 +0000 | [diff] [blame^] | 64 | object's :attr:`~object.__dict__`; if *NULL*, a new dictionary will be created for the |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 65 | instance. |