blob: 68bebc8a9abcba6cf89e3477b202afe8b9dbb96e [file] [log] [blame]
Georg Brandlf6842722008-01-19 22:08:21 +00001.. highlightlang:: c
2
3.. _typeobjects:
4
5Type Objects
6------------
7
8.. index:: object: type
9
10
Sandro Tosi98ed08f2012-01-14 16:42:02 +010011.. c:type:: PyTypeObject
Georg Brandlf6842722008-01-19 22:08:21 +000012
13 The C structure of the objects used to describe built-in types.
14
15
Sandro Tosi98ed08f2012-01-14 16:42:02 +010016.. c:var:: PyObject* PyType_Type
Georg Brandlf6842722008-01-19 22:08:21 +000017
18 .. index:: single: TypeType (in module types)
19
20 This is the type object for type objects; it is the same object as ``type`` and
21 ``types.TypeType`` in the Python layer.
22
23
Sandro Tosi98ed08f2012-01-14 16:42:02 +010024.. c:function:: int PyType_Check(PyObject *o)
Georg Brandlf6842722008-01-19 22:08:21 +000025
26 Return true if the object *o* is a type object, including instances of types
27 derived from the standard type object. Return false in all other cases.
28
29
Sandro Tosi98ed08f2012-01-14 16:42:02 +010030.. c:function:: int PyType_CheckExact(PyObject *o)
Georg Brandlf6842722008-01-19 22:08:21 +000031
32 Return true if the object *o* is a type object, but not a subtype of the
33 standard type object. Return false in all other cases.
34
35 .. versionadded:: 2.2
36
37
Sandro Tosi98ed08f2012-01-14 16:42:02 +010038.. c:function:: unsigned int PyType_ClearCache()
Christian Heimes908caac2008-01-27 23:34:59 +000039
Georg Brandl74a1dea2008-05-28 11:21:39 +000040 Clear the internal lookup cache. Return the current version tag.
41
42 .. versionadded:: 2.6
43
44
Sandro Tosi98ed08f2012-01-14 16:42:02 +010045.. c:function:: void PyType_Modified(PyTypeObject *type)
Georg Brandl74a1dea2008-05-28 11:21:39 +000046
47 Invalidate the internal lookup cache for the type and all of its
48 subtypes. This function must be called after any manual
49 modification of the attributes or base classes of the type.
Christian Heimes908caac2008-01-27 23:34:59 +000050
51 .. versionadded:: 2.6
52
53
Sandro Tosi98ed08f2012-01-14 16:42:02 +010054.. c:function:: int PyType_HasFeature(PyObject *o, int feature)
Georg Brandlf6842722008-01-19 22:08:21 +000055
56 Return true if the type object *o* sets the feature *feature*. Type features
57 are denoted by single bit flags.
58
59
Sandro Tosi98ed08f2012-01-14 16:42:02 +010060.. c:function:: int PyType_IS_GC(PyObject *o)
Georg Brandlf6842722008-01-19 22:08:21 +000061
62 Return true if the type object includes support for the cycle detector; this
63 tests the type flag :const:`Py_TPFLAGS_HAVE_GC`.
64
65 .. versionadded:: 2.0
66
67
Sandro Tosi98ed08f2012-01-14 16:42:02 +010068.. c:function:: int PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b)
Georg Brandlf6842722008-01-19 22:08:21 +000069
70 Return true if *a* is a subtype of *b*.
71
72 .. versionadded:: 2.2
73
Georg Brandlb74cf542014-10-06 14:15:06 +020074 This function only checks for actual subtypes, which means that
Georg Brandl8b14dd32014-10-06 16:21:08 +020075 :meth:`~class.__subclasscheck__` is not called on *b*. Call
Georg Brandlb74cf542014-10-06 14:15:06 +020076 :c:func:`PyObject_IsSubclass` to do the same check that :func:`issubclass`
77 would do.
78
Georg Brandlf6842722008-01-19 22:08:21 +000079
Sandro Tosi98ed08f2012-01-14 16:42:02 +010080.. c:function:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
Georg Brandlf6842722008-01-19 22:08:21 +000081
82 .. versionadded:: 2.2
83
Jeroen Ruigrok van der Werven089c5cd2009-04-25 17:59:03 +000084 .. versionchanged:: 2.5
Sandro Tosi98ed08f2012-01-14 16:42:02 +010085 This function used an :c:type:`int` type for *nitems*. This might require
Jeroen Ruigrok van der Werven089c5cd2009-04-25 17:59:03 +000086 changes in your code for properly supporting 64-bit systems.
87
Georg Brandlf6842722008-01-19 22:08:21 +000088
Sandro Tosi98ed08f2012-01-14 16:42:02 +010089.. c:function:: PyObject* PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
Georg Brandlf6842722008-01-19 22:08:21 +000090
91 .. versionadded:: 2.2
92
93
Sandro Tosi98ed08f2012-01-14 16:42:02 +010094.. c:function:: int PyType_Ready(PyTypeObject *type)
Georg Brandlf6842722008-01-19 22:08:21 +000095
96 Finalize a type object. This should be called on all type objects to finish
97 their initialization. This function is responsible for adding inherited slots
98 from a type's base class. Return ``0`` on success, or return ``-1`` and sets an
99 exception on error.
100
101 .. versionadded:: 2.2