blob: d4a76b611bd08a95e5bcfafb5affcd7e2e020e71 [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
Raymond Hettingera1993682011-01-27 01:20:32 +00007**Source code:** :source:`Lib/types.py`
8
9--------------
Georg Brandl116aa622007-08-15 14:28:22 +000010
11This module defines names for some object types that are used by the standard
Georg Brandld66a0292008-08-23 15:14:57 +000012Python interpreter, but not exposed as builtins like :class:`int` or
13:class:`str` are. Also, it does not include some of the types that arise
14transparently during processing such as the ``listiterator`` type.
Georg Brandl116aa622007-08-15 14:28:22 +000015
Georg Brandld66a0292008-08-23 15:14:57 +000016Typical use is for :func:`isinstance` or :func:`issubclass` checks.
Christian Heimesc9543e42007-11-28 08:28:28 +000017
Georg Brandl116aa622007-08-15 14:28:22 +000018The module defines the following names:
19
Georg Brandl116aa622007-08-15 14:28:22 +000020.. data:: FunctionType
Georg Brandla1e9ef72007-09-04 07:23:09 +000021 LambdaType
Georg Brandl116aa622007-08-15 14:28:22 +000022
Georg Brandld66a0292008-08-23 15:14:57 +000023 The type of user-defined functions and functions created by :keyword:`lambda`
24 expressions.
Georg Brandl116aa622007-08-15 14:28:22 +000025
26
Georg Brandl116aa622007-08-15 14:28:22 +000027.. data:: GeneratorType
28
Georg Brandl9afde1c2007-11-01 20:32:30 +000029 The type of :term:`generator`-iterator objects, produced by calling a
30 generator function.
Georg Brandl116aa622007-08-15 14:28:22 +000031
Georg Brandl116aa622007-08-15 14:28:22 +000032
33.. data:: CodeType
34
35 .. index:: builtin: compile
36
37 The type for code objects such as returned by :func:`compile`.
38
39
Georg Brandl116aa622007-08-15 14:28:22 +000040.. data:: MethodType
41
42 The type of methods of user-defined class instances.
43
44
Georg Brandl116aa622007-08-15 14:28:22 +000045.. data:: BuiltinFunctionType
Georg Brandla1e9ef72007-09-04 07:23:09 +000046 BuiltinMethodType
Georg Brandl116aa622007-08-15 14:28:22 +000047
Georg Brandld66a0292008-08-23 15:14:57 +000048 The type of built-in functions like :func:`len` or :func:`sys.exit`, and
49 methods of built-in classes. (Here, the term "built-in" means "written in
50 C".)
Georg Brandl116aa622007-08-15 14:28:22 +000051
52
Georg Brandl116aa622007-08-15 14:28:22 +000053.. data:: ModuleType
54
55 The type of modules.
56
57
Georg Brandl116aa622007-08-15 14:28:22 +000058.. data:: TracebackType
59
60 The type of traceback objects such as found in ``sys.exc_info()[2]``.
61
62
63.. data:: FrameType
64
65 The type of frame objects such as found in ``tb.tb_frame`` if ``tb`` is a
66 traceback object.
67
68
Georg Brandl116aa622007-08-15 14:28:22 +000069.. data:: GetSetDescriptorType
70
Christian Heimes5e696852008-04-09 08:37:03 +000071 The type of objects defined in extension modules with ``PyGetSetDef``, such
72 as ``FrameType.f_locals`` or ``array.array.typecode``. This type is used as
73 descriptor for object attributes; it has the same purpose as the
74 :class:`property` type, but for classes defined in extension modules.
Georg Brandl116aa622007-08-15 14:28:22 +000075
Georg Brandl116aa622007-08-15 14:28:22 +000076
77.. data:: MemberDescriptorType
78
Christian Heimes5e696852008-04-09 08:37:03 +000079 The type of objects defined in extension modules with ``PyMemberDef``, such
80 as ``datetime.timedelta.days``. This type is used as descriptor for simple C
81 data members which use standard conversion functions; it has the same purpose
82 as the :class:`property` type, but for classes defined in extension modules.
Georg Brandl495f7b52009-10-27 15:28:25 +000083
84 .. impl-detail::
85
86 In other implementations of Python, this type may be identical to
87 ``GetSetDescriptorType``.