]>
Commit | Line | Data |
---|---|---|
3257aa99 DM |
1 | """Define names for all type symbols known in the standard interpreter.\r |
2 | \r | |
3 | Types that are part of optional modules (e.g. array) are not listed.\r | |
4 | """\r | |
5 | import sys\r | |
6 | \r | |
7 | # Iterators in Python aren't a matter of type but of protocol. A large\r | |
8 | # and changing number of builtin types implement *some* flavor of\r | |
9 | # iterator. Don't check the type! Use hasattr to check for both\r | |
10 | # "__iter__" and "next" attributes instead.\r | |
11 | \r | |
12 | NoneType = type(None)\r | |
13 | TypeType = type\r | |
14 | ObjectType = object\r | |
15 | \r | |
16 | IntType = int\r | |
17 | LongType = long\r | |
18 | FloatType = float\r | |
19 | BooleanType = bool\r | |
20 | try:\r | |
21 | ComplexType = complex\r | |
22 | except NameError:\r | |
23 | pass\r | |
24 | \r | |
25 | StringType = str\r | |
26 | \r | |
27 | # StringTypes is already outdated. Instead of writing "type(x) in\r | |
28 | # types.StringTypes", you should use "isinstance(x, basestring)". But\r | |
29 | # we keep around for compatibility with Python 2.2.\r | |
30 | try:\r | |
31 | UnicodeType = unicode\r | |
32 | StringTypes = (StringType, UnicodeType)\r | |
33 | except NameError:\r | |
34 | StringTypes = (StringType,)\r | |
35 | \r | |
36 | BufferType = buffer\r | |
37 | \r | |
38 | TupleType = tuple\r | |
39 | ListType = list\r | |
40 | DictType = DictionaryType = dict\r | |
41 | \r | |
42 | def _f(): pass\r | |
43 | FunctionType = type(_f)\r | |
44 | LambdaType = type(lambda: None) # Same as FunctionType\r | |
45 | CodeType = type(_f.func_code)\r | |
46 | \r | |
47 | def _g():\r | |
48 | yield 1\r | |
49 | GeneratorType = type(_g())\r | |
50 | \r | |
51 | class _C:\r | |
52 | def _m(self): pass\r | |
53 | ClassType = type(_C)\r | |
54 | UnboundMethodType = type(_C._m) # Same as MethodType\r | |
55 | _x = _C()\r | |
56 | InstanceType = type(_x)\r | |
57 | MethodType = type(_x._m)\r | |
58 | \r | |
59 | BuiltinFunctionType = type(len)\r | |
60 | BuiltinMethodType = type([].append) # Same as BuiltinFunctionType\r | |
61 | \r | |
62 | ModuleType = type(sys)\r | |
63 | FileType = file\r | |
64 | XRangeType = xrange\r | |
65 | \r | |
66 | try:\r | |
67 | raise TypeError\r | |
68 | except TypeError:\r | |
69 | tb = sys.exc_info()[2]\r | |
70 | TracebackType = type(tb)\r | |
71 | FrameType = type(tb.tb_frame)\r | |
72 | del tb\r | |
73 | \r | |
74 | SliceType = slice\r | |
75 | EllipsisType = type(Ellipsis)\r | |
76 | \r | |
77 | DictProxyType = type(TypeType.__dict__)\r | |
78 | NotImplementedType = type(NotImplemented)\r | |
79 | \r | |
80 | # For Jython, the following two types are identical\r | |
81 | GetSetDescriptorType = type(FunctionType.func_code)\r | |
82 | MemberDescriptorType = type(FunctionType.func_globals)\r | |
83 | \r | |
84 | del sys, _f, _g, _C, _x # Not for export\r | |
85 | \r | |
86 | __all__ = list(n for n in globals() if n[:1] != '_')\r |