/Doc/c-api/type.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 96 lines · 49 code · 47 blank · 0 comment · 0 complexity · dc49b6bc221aaec840c6f6cb4af02fa4 MD5 · raw file

  1. .. highlightlang:: c
  2. .. _typeobjects:
  3. Type Objects
  4. ------------
  5. .. index:: object: type
  6. .. ctype:: PyTypeObject
  7. The C structure of the objects used to describe built-in types.
  8. .. cvar:: PyObject* PyType_Type
  9. .. index:: single: TypeType (in module types)
  10. This is the type object for type objects; it is the same object as ``type`` and
  11. ``types.TypeType`` in the Python layer.
  12. .. cfunction:: int PyType_Check(PyObject *o)
  13. Return true if the object *o* is a type object, including instances of types
  14. derived from the standard type object. Return false in all other cases.
  15. .. cfunction:: int PyType_CheckExact(PyObject *o)
  16. Return true if the object *o* is a type object, but not a subtype of the
  17. standard type object. Return false in all other cases.
  18. .. versionadded:: 2.2
  19. .. cfunction:: unsigned int PyType_ClearCache(void)
  20. Clear the internal lookup cache. Return the current version tag.
  21. .. versionadded:: 2.6
  22. .. cfunction:: void PyType_Modified(PyTypeObject *type)
  23. Invalidate the internal lookup cache for the type and all of its
  24. subtypes. This function must be called after any manual
  25. modification of the attributes or base classes of the type.
  26. .. versionadded:: 2.6
  27. .. cfunction:: int PyType_HasFeature(PyObject *o, int feature)
  28. Return true if the type object *o* sets the feature *feature*. Type features
  29. are denoted by single bit flags.
  30. .. cfunction:: int PyType_IS_GC(PyObject *o)
  31. Return true if the type object includes support for the cycle detector; this
  32. tests the type flag :const:`Py_TPFLAGS_HAVE_GC`.
  33. .. versionadded:: 2.0
  34. .. cfunction:: int PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b)
  35. Return true if *a* is a subtype of *b*.
  36. .. versionadded:: 2.2
  37. .. cfunction:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
  38. .. versionadded:: 2.2
  39. .. versionchanged:: 2.5
  40. This function used an :ctype:`int` type for *nitems*. This might require
  41. changes in your code for properly supporting 64-bit systems.
  42. .. cfunction:: PyObject* PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
  43. .. versionadded:: 2.2
  44. .. cfunction:: int PyType_Ready(PyTypeObject *type)
  45. Finalize a type object. This should be called on all type objects to finish
  46. their initialization. This function is responsible for adding inherited slots
  47. from a type's base class. Return ``0`` on success, or return ``-1`` and sets an
  48. exception on error.
  49. .. versionadded:: 2.2