blob: 7caecaf4f6fca5479b66c39eac057a51ffa94f50 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`types` --- Names for built-in types
2=========================================
3
4.. module:: types
5 :synopsis: Names for built-in types.
6
7
8This module defines names for some object types that are used by the standard
Georg Brandld66a0292008-08-23 15:14:57 +00009Python interpreter, but not exposed as builtins like :class:`int` or
10:class:`str` are. Also, it does not include some of the types that arise
11transparently during processing such as the ``listiterator`` type.
Georg Brandl116aa622007-08-15 14:28:22 +000012
Georg Brandld66a0292008-08-23 15:14:57 +000013Typical use is for :func:`isinstance` or :func:`issubclass` checks.
Christian Heimesc9543e42007-11-28 08:28:28 +000014
Georg Brandl116aa622007-08-15 14:28:22 +000015The module defines the following names:
16
Georg Brandl116aa622007-08-15 14:28:22 +000017.. data:: FunctionType
Georg Brandla1e9ef72007-09-04 07:23:09 +000018 LambdaType
Georg Brandl116aa622007-08-15 14:28:22 +000019
Georg Brandld66a0292008-08-23 15:14:57 +000020 The type of user-defined functions and functions created by :keyword:`lambda`
21 expressions.
Georg Brandl116aa622007-08-15 14:28:22 +000022
23
Georg Brandl116aa622007-08-15 14:28:22 +000024.. data:: GeneratorType
25
Georg Brandl9afde1c2007-11-01 20:32:30 +000026 The type of :term:`generator`-iterator objects, produced by calling a
27 generator function.
Georg Brandl116aa622007-08-15 14:28:22 +000028
Georg Brandl116aa622007-08-15 14:28:22 +000029
30.. data:: CodeType
31
32 .. index:: builtin: compile
33
34 The type for code objects such as returned by :func:`compile`.
35
36
Georg Brandl116aa622007-08-15 14:28:22 +000037.. data:: MethodType
38
39 The type of methods of user-defined class instances.
40
41
Georg Brandl116aa622007-08-15 14:28:22 +000042.. data:: BuiltinFunctionType
Georg Brandla1e9ef72007-09-04 07:23:09 +000043 BuiltinMethodType
Georg Brandl116aa622007-08-15 14:28:22 +000044
Georg Brandld66a0292008-08-23 15:14:57 +000045 The type of built-in functions like :func:`len` or :func:`sys.exit`, and
46 methods of built-in classes. (Here, the term "built-in" means "written in
47 C".)
Georg Brandl116aa622007-08-15 14:28:22 +000048
49
Georg Brandl116aa622007-08-15 14:28:22 +000050.. data:: ModuleType
51
52 The type of modules.
53
54
Georg Brandl116aa622007-08-15 14:28:22 +000055.. data:: TracebackType
56
57 The type of traceback objects such as found in ``sys.exc_info()[2]``.
58
59
60.. data:: FrameType
61
62 The type of frame objects such as found in ``tb.tb_frame`` if ``tb`` is a
63 traceback object.
64
65
Georg Brandl116aa622007-08-15 14:28:22 +000066.. data:: GetSetDescriptorType
67
Christian Heimes5e696852008-04-09 08:37:03 +000068 The type of objects defined in extension modules with ``PyGetSetDef``, such
69 as ``FrameType.f_locals`` or ``array.array.typecode``. This type is used as
70 descriptor for object attributes; it has the same purpose as the
71 :class:`property` type, but for classes defined in extension modules.
Georg Brandl116aa622007-08-15 14:28:22 +000072
Georg Brandl116aa622007-08-15 14:28:22 +000073
74.. data:: MemberDescriptorType
75
Christian Heimes5e696852008-04-09 08:37:03 +000076 The type of objects defined in extension modules with ``PyMemberDef``, such
77 as ``datetime.timedelta.days``. This type is used as descriptor for simple C
78 data members which use standard conversion functions; it has the same purpose
79 as the :class:`property` type, but for classes defined in extension modules.
Georg Brandl495f7b52009-10-27 15:28:25 +000080
81 .. impl-detail::
82
83 In other implementations of Python, this type may be identical to
84 ``GetSetDescriptorType``.