Merged release21-maint changes.
[python/dscho.git] / Lib / types.py
blob01af46364013ab6785bd0f4151f448cd09ddd058
1 """Define names for all type symbols known in the standard interpreter.
3 Types that are part of optional modules (e.g. array) are not listed.
4 """
5 from __future__ import generators
7 import sys
9 NoneType = type(None)
10 TypeType = type
11 ObjectType = object
13 IntType = int
14 LongType = long
15 FloatType = float
16 try:
17 ComplexType = complex
18 except NameError:
19 pass
21 StringType = str
22 UnicodeType = unicode
23 BufferType = type(buffer(''))
25 TupleType = tuple
26 ListType = list
27 DictType = DictionaryType = dictionary
29 def _f(): pass
30 FunctionType = type(_f)
31 LambdaType = type(lambda: None) # Same as FunctionType
32 try:
33 CodeType = type(_f.func_code)
34 except RuntimeError:
35 # Execution in restricted environment
36 pass
38 def g():
39 yield 1
40 GeneratorType = type(g())
41 del g
43 class _C:
44 def _m(self): pass
45 ClassType = type(_C)
46 UnboundMethodType = type(_C._m) # Same as MethodType
47 _x = _C()
48 InstanceType = type(_x)
49 MethodType = type(_x._m)
51 BuiltinFunctionType = type(len)
52 BuiltinMethodType = type([].append) # Same as BuiltinFunctionType
54 ModuleType = type(sys)
56 try:
57 FileType = type(sys.__stdin__)
58 except AttributeError:
59 # Not available in restricted mode
60 pass
61 XRangeType = type(xrange(0))
63 try:
64 raise TypeError
65 except TypeError:
66 try:
67 tb = sys.exc_info()[2]
68 TracebackType = type(tb)
69 FrameType = type(tb.tb_frame)
70 except AttributeError:
71 # In the restricted environment, exc_info returns (None, None,
72 # None) Then, tb.tb_frame gives an attribute error
73 pass
74 tb = None; del tb
76 SliceType = type(slice(0))
77 EllipsisType = type(Ellipsis)
79 DictIterType = type(iter({}))
80 SequenceIterType = type(iter([]))
81 FunctionIterType = type(iter(lambda: 0, 0))
82 DictProxyType = type(TypeType.__dict__)
84 del sys, _f, _C, _x # Not for export