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 | 898c915 | 1997-09-04 22:12:34 +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: |
Guido van Rossum | 898c915 | 1997-09-04 22:12:34 +0000 | [diff] [blame] | 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 |
Guido van Rossum | 898c915 | 1997-09-04 22:12:34 +0000 | [diff] [blame] | 26 | try: |
| 27 | CodeType = type(_f.func_code) |
| 28 | except: |
| 29 | pass |
Guido van Rossum | 85d8945 | 1994-06-23 11:53:27 +0000 | [diff] [blame] | 30 | |
Guido van Rossum | adc940e | 1994-09-29 10:04:43 +0000 | [diff] [blame] | 31 | class _C: |
Guido van Rossum | 898c915 | 1997-09-04 22:12:34 +0000 | [diff] [blame] | 32 | def _m(self): pass |
Guido van Rossum | adc940e | 1994-09-29 10:04:43 +0000 | [diff] [blame] | 33 | ClassType = type(_C) |
| 34 | UnboundMethodType = type(_C._m) # Same as MethodType |
| 35 | _x = _C() |
| 36 | InstanceType = type(_x) |
| 37 | MethodType = type(_x._m) |
Guido van Rossum | 85d8945 | 1994-06-23 11:53:27 +0000 | [diff] [blame] | 38 | |
Guido van Rossum | adc940e | 1994-09-29 10:04:43 +0000 | [diff] [blame] | 39 | BuiltinFunctionType = type(len) |
| 40 | BuiltinMethodType = type([].append) # Same as BuiltinFunctionType |
Guido van Rossum | 85d8945 | 1994-06-23 11:53:27 +0000 | [diff] [blame] | 41 | |
| 42 | ModuleType = type(sys) |
| 43 | |
Guido van Rossum | 898c915 | 1997-09-04 22:12:34 +0000 | [diff] [blame] | 44 | try: |
| 45 | FileType = type(sys.stdin) # XXX what if it was assigned to? |
| 46 | except: |
| 47 | pass |
Guido van Rossum | 85d8945 | 1994-06-23 11:53:27 +0000 | [diff] [blame] | 48 | XRangeType = type(xrange(0)) |
| 49 | |
| 50 | try: |
Guido van Rossum | 898c915 | 1997-09-04 22:12:34 +0000 | [diff] [blame] | 51 | raise TypeError |
Guido van Rossum | 85d8945 | 1994-06-23 11:53:27 +0000 | [diff] [blame] | 52 | except TypeError: |
Guido van Rossum | 898c915 | 1997-09-04 22:12:34 +0000 | [diff] [blame] | 53 | try: |
Guido van Rossum | 85d8945 | 1994-06-23 11:53:27 +0000 | [diff] [blame] | 54 | TracebackType = type(sys.exc_traceback) |
| 55 | FrameType = type(sys.exc_traceback.tb_frame) |
Guido van Rossum | 898c915 | 1997-09-04 22:12:34 +0000 | [diff] [blame] | 56 | except: |
| 57 | pass |
Guido van Rossum | 85d8945 | 1994-06-23 11:53:27 +0000 | [diff] [blame] | 58 | |
Guido van Rossum | 8741b2b | 1996-10-11 16:00:06 +0000 | [diff] [blame] | 59 | SliceType = type(slice(0)) |
Guido van Rossum | e449af7 | 1996-10-11 16:25:41 +0000 | [diff] [blame] | 60 | EllipsisType = type(Ellipsis) |
Guido van Rossum | 8741b2b | 1996-10-11 16:00:06 +0000 | [diff] [blame] | 61 | |
Guido van Rossum | adc940e | 1994-09-29 10:04:43 +0000 | [diff] [blame] | 62 | del sys, _f, _C, _x # Not for export |