8
.. index:: object: type
11
.. c:type:: PyTypeObject
13
The C structure of the objects used to describe built-in types.
16
.. c:var:: PyObject* PyType_Type
18
This is the type object for type objects; it is the same object as
19
:class:`type` in the Python layer.
22
.. c:function:: int PyType_Check(PyObject *o)
24
Return true if the object *o* is a type object, including instances of types
25
derived from the standard type object. Return false in all other cases.
28
.. c:function:: int PyType_CheckExact(PyObject *o)
30
Return true if the object *o* is a type object, but not a subtype of the
31
standard type object. Return false in all other cases.
34
.. c:function:: unsigned int PyType_ClearCache()
36
Clear the internal lookup cache. Return the current version tag.
38
.. c:function:: long PyType_GetFlags(PyTypeObject* type)
40
Return the :c:member:`~PyTypeObject.tp_flags` member of *type*. This function is primarily
41
meant for use with `Py_LIMITED_API`; the individual flag bits are
42
guaranteed to be stable across Python releases, but access to
43
:c:member:`~PyTypeObject.tp_flags` itself is not part of the limited API.
47
.. c:function:: void PyType_Modified(PyTypeObject *type)
49
Invalidate the internal lookup cache for the type and all of its
50
subtypes. This function must be called after any manual
51
modification of the attributes or base classes of the type.
54
.. c:function:: int PyType_HasFeature(PyTypeObject *o, int feature)
56
Return true if the type object *o* sets the feature *feature*. Type features
57
are denoted by single bit flags.
60
.. c:function:: int PyType_IS_GC(PyTypeObject *o)
62
Return true if the type object includes support for the cycle detector; this
63
tests the type flag :const:`Py_TPFLAGS_HAVE_GC`.
66
.. c:function:: int PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b)
68
Return true if *a* is a subtype of *b*.
71
.. c:function:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
73
Generic handler for the :c:member:`~PyTypeObject.tp_alloc` slot of a type object. Use
74
Python's default memory allocation mechanism to allocate a new instance and
75
initialize all its contents to *NULL*.
77
.. c:function:: PyObject* PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
79
Generic handler for the :c:member:`~PyTypeObject.tp_new` slot of a type object. Create a
80
new instance using the type's :c:member:`~PyTypeObject.tp_alloc` slot.
82
.. c:function:: int PyType_Ready(PyTypeObject *type)
84
Finalize a type object. This should be called on all type objects to finish
85
their initialization. This function is responsible for adding inherited slots
86
from a type's base class. Return ``0`` on success, or return ``-1`` and sets an
89
.. c:function:: PyObject* PyType_FromSpec(PyType_Spec *spec)
91
Creates and returns a heap type object from the *spec* passed to the function.
93
.. c:function:: PyObject* PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
95
Creates and returns a heap type object from the *spec*. In addition to that,
96
the created heap type contains all types contained by the *bases* tuple as base
97
types. This allows the caller to reference other heap types as base types.