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 | |
| 7 | |
| 8 | 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] | 9 | Python 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 |
| 11 | transparently during processing such as the ``listiterator`` type. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 12 | |
Georg Brandl | d66a029 | 2008-08-23 15:14:57 +0000 | [diff] [blame] | 13 | Typical use is for :func:`isinstance` or :func:`issubclass` checks. |
Christian Heimes | c9543e4 | 2007-11-28 08:28:28 +0000 | [diff] [blame] | 14 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 15 | The module defines the following names: |
| 16 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 17 | .. data:: FunctionType |
Georg Brandl | a1e9ef7 | 2007-09-04 07:23:09 +0000 | [diff] [blame] | 18 | LambdaType |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 19 | |
Georg Brandl | d66a029 | 2008-08-23 15:14:57 +0000 | [diff] [blame] | 20 | The type of user-defined functions and functions created by :keyword:`lambda` |
| 21 | expressions. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 22 | |
| 23 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 24 | .. data:: GeneratorType |
| 25 | |
Georg Brandl | 9afde1c | 2007-11-01 20:32:30 +0000 | [diff] [blame] | 26 | The type of :term:`generator`-iterator objects, produced by calling a |
| 27 | generator function. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 28 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 29 | |
| 30 | .. data:: CodeType |
| 31 | |
| 32 | .. index:: builtin: compile |
| 33 | |
| 34 | The type for code objects such as returned by :func:`compile`. |
| 35 | |
| 36 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 37 | .. data:: MethodType |
| 38 | |
| 39 | The type of methods of user-defined class instances. |
| 40 | |
| 41 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 42 | .. data:: BuiltinFunctionType |
Georg Brandl | a1e9ef7 | 2007-09-04 07:23:09 +0000 | [diff] [blame] | 43 | BuiltinMethodType |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 44 | |
Georg Brandl | d66a029 | 2008-08-23 15:14:57 +0000 | [diff] [blame] | 45 | 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 Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 48 | |
| 49 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 50 | .. data:: ModuleType |
| 51 | |
| 52 | The type of modules. |
| 53 | |
| 54 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 55 | .. 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 Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 66 | .. data:: GetSetDescriptorType |
| 67 | |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 68 | 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 Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 72 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 73 | |
| 74 | .. data:: MemberDescriptorType |
| 75 | |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 76 | 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 Brandl | 628e6f9 | 2009-10-27 20:24:45 +0000 | [diff] [blame] | 80 | |
| 81 | .. impl-detail:: |
| 82 | |
| 83 | In other implementations of Python, this type may be identical to |
| 84 | ``GetSetDescriptorType``. |