Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | :mod:`types` --- Names for built-in types |
| 2 | ========================================= |
| 3 | |
| 4 | .. module:: types |
| 5 | :synopsis: Names for built-in types. |
| 6 | |
Raymond Hettinger | a199368 | 2011-01-27 01:20:32 +0000 | [diff] [blame^] | 7 | **Source code:** :source:`Lib/types.py` |
| 8 | |
| 9 | -------------- |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 10 | |
| 11 | This module defines names for some object types that are used by the standard |
Georg Brandl | d66a029 | 2008-08-23 15:14:57 +0000 | [diff] [blame] | 12 | Python 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 |
| 14 | transparently during processing such as the ``listiterator`` type. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 15 | |
Georg Brandl | d66a029 | 2008-08-23 15:14:57 +0000 | [diff] [blame] | 16 | Typical use is for :func:`isinstance` or :func:`issubclass` checks. |
Christian Heimes | c9543e4 | 2007-11-28 08:28:28 +0000 | [diff] [blame] | 17 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 18 | The module defines the following names: |
| 19 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 20 | .. data:: FunctionType |
Georg Brandl | a1e9ef7 | 2007-09-04 07:23:09 +0000 | [diff] [blame] | 21 | LambdaType |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 22 | |
Georg Brandl | d66a029 | 2008-08-23 15:14:57 +0000 | [diff] [blame] | 23 | The type of user-defined functions and functions created by :keyword:`lambda` |
| 24 | expressions. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 25 | |
| 26 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 27 | .. data:: GeneratorType |
| 28 | |
Georg Brandl | 9afde1c | 2007-11-01 20:32:30 +0000 | [diff] [blame] | 29 | The type of :term:`generator`-iterator objects, produced by calling a |
| 30 | generator function. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 31 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 32 | |
| 33 | .. data:: CodeType |
| 34 | |
| 35 | .. index:: builtin: compile |
| 36 | |
| 37 | The type for code objects such as returned by :func:`compile`. |
| 38 | |
| 39 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 40 | .. data:: MethodType |
| 41 | |
| 42 | The type of methods of user-defined class instances. |
| 43 | |
| 44 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 45 | .. data:: BuiltinFunctionType |
Georg Brandl | a1e9ef7 | 2007-09-04 07:23:09 +0000 | [diff] [blame] | 46 | BuiltinMethodType |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 47 | |
Georg Brandl | d66a029 | 2008-08-23 15:14:57 +0000 | [diff] [blame] | 48 | 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 Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 51 | |
| 52 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 53 | .. data:: ModuleType |
| 54 | |
| 55 | The type of modules. |
| 56 | |
| 57 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 58 | .. 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 Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 69 | .. data:: GetSetDescriptorType |
| 70 | |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 71 | 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 Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 75 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 76 | |
| 77 | .. data:: MemberDescriptorType |
| 78 | |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 79 | 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 Brandl | 495f7b5 | 2009-10-27 15:28:25 +0000 | [diff] [blame] | 83 | |
| 84 | .. impl-detail:: |
| 85 | |
| 86 | In other implementations of Python, this type may be identical to |
| 87 | ``GetSetDescriptorType``. |