Guido van Rossum | 85d8945 | 1994-06-23 11:53:27 +0000 | [diff] [blame] | 1 | # Define names for all type symbols known in the standard interpreter. |
| 2 | # Types that are part of optional modules (e.g. array) are not listed. |
| 3 | |
| 4 | import sys |
| 5 | |
| 6 | NoneType = type(None) |
| 7 | TypeType = type(NoneType) |
| 8 | |
| 9 | IntType = type(0) |
| 10 | LongType = type(0L) |
| 11 | FloatType = type(0.0) |
Guido van Rossum | 0f6f812 | 1996-02-13 00:04:31 +0000 | [diff] [blame] | 12 | try: |
Guido van Rossum | 06d7441 | 1996-01-25 17:31:58 +0000 | [diff] [blame] | 13 | ComplexType = type(complex(0,1)) |
Guido van Rossum | 0f6f812 | 1996-02-13 00:04:31 +0000 | [diff] [blame] | 14 | except NameError: |
| 15 | pass |
Guido van Rossum | 85d8945 | 1994-06-23 11:53:27 +0000 | [diff] [blame] | 16 | |
| 17 | StringType = type('') |
| 18 | |
| 19 | TupleType = type(()) |
| 20 | ListType = type([]) |
Guido van Rossum | 780620f | 1995-02-27 13:14:15 +0000 | [diff] [blame] | 21 | DictType = DictionaryType = type({}) |
Guido van Rossum | 85d8945 | 1994-06-23 11:53:27 +0000 | [diff] [blame] | 22 | |
Guido van Rossum | adc940e | 1994-09-29 10:04:43 +0000 | [diff] [blame] | 23 | def _f(): pass |
| 24 | FunctionType = type(_f) |
| 25 | LambdaType = type(lambda: None) # Same as FunctionType |
| 26 | CodeType = type(_f.func_code) |
Guido van Rossum | 85d8945 | 1994-06-23 11:53:27 +0000 | [diff] [blame] | 27 | |
Guido van Rossum | adc940e | 1994-09-29 10:04:43 +0000 | [diff] [blame] | 28 | class _C: |
| 29 | def _m(self): pass |
| 30 | ClassType = type(_C) |
| 31 | UnboundMethodType = type(_C._m) # Same as MethodType |
| 32 | _x = _C() |
| 33 | InstanceType = type(_x) |
| 34 | MethodType = type(_x._m) |
Guido van Rossum | 85d8945 | 1994-06-23 11:53:27 +0000 | [diff] [blame] | 35 | |
Guido van Rossum | adc940e | 1994-09-29 10:04:43 +0000 | [diff] [blame] | 36 | BuiltinFunctionType = type(len) |
| 37 | BuiltinMethodType = type([].append) # Same as BuiltinFunctionType |
Guido van Rossum | 85d8945 | 1994-06-23 11:53:27 +0000 | [diff] [blame] | 38 | |
| 39 | ModuleType = type(sys) |
| 40 | |
Guido van Rossum | adc940e | 1994-09-29 10:04:43 +0000 | [diff] [blame] | 41 | FileType = type(sys.stdin) # XXX what if it was assigned to? |
Guido van Rossum | 85d8945 | 1994-06-23 11:53:27 +0000 | [diff] [blame] | 42 | XRangeType = type(xrange(0)) |
| 43 | |
| 44 | try: |
| 45 | raise TypeError |
| 46 | except TypeError: |
| 47 | TracebackType = type(sys.exc_traceback) |
| 48 | FrameType = type(sys.exc_traceback.tb_frame) |
| 49 | |
Guido van Rossum | adc940e | 1994-09-29 10:04:43 +0000 | [diff] [blame] | 50 | del sys, _f, _C, _x # Not for export |