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) |
| 12 | |
| 13 | StringType = type('') |
| 14 | |
| 15 | TupleType = type(()) |
| 16 | ListType = type([]) |
| 17 | DictionaryType = type({}) |
| 18 | |
| 19 | def func(): pass |
| 20 | FunctionType = type(func) |
| 21 | |
| 22 | class C: |
| 23 | def meth(self): pass |
| 24 | ClassType = type(C) |
| 25 | UnboundMethodType = type(C.meth) # Same as MethodType |
| 26 | x = C() |
| 27 | InstanceType = type(x) |
| 28 | MethodType = type(x.meth) |
| 29 | |
| 30 | BuiltinFunctionType = type(len) # Also used for built-in methods |
| 31 | |
| 32 | ModuleType = type(sys) |
| 33 | |
| 34 | FileType = type(sys.stdin) |
| 35 | XRangeType = type(xrange(0)) |
| 36 | |
| 37 | try: |
| 38 | raise TypeError |
| 39 | except TypeError: |
| 40 | TracebackType = type(sys.exc_traceback) |
| 41 | FrameType = type(sys.exc_traceback.tb_frame) |
| 42 | |
| 43 | del sys, func, C, x # These are not for export |