Added WatchedFileHandler (based on SF patch #1598415)
[python.git] / Lib / types.py
blob6c8c2b26f392459c57d7f49a8d9c4fffce2a2d7f
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 import sys
7 # Iterators in Python aren't a matter of type but of protocol. A large
8 # and changing number of builtin types implement *some* flavor of
9 # iterator. Don't check the type! Use hasattr to check for both
10 # "__iter__" and "next" attributes instead.
12 NoneType = type(None)
13 TypeType = type
14 ObjectType = object
16 IntType = int
17 LongType = long
18 FloatType = float
19 BooleanType = bool
20 try:
21 ComplexType = complex
22 except NameError:
23 pass
25 StringType = str
27 # StringTypes is already outdated. Instead of writing "type(x) in
28 # types.StringTypes", you should use "isinstance(x, basestring)". But
29 # we keep around for compatibility with Python 2.2.
30 try:
31 UnicodeType = unicode
32 StringTypes = (StringType, UnicodeType)
33 except NameError:
34 StringTypes = (StringType,)
36 BufferType = buffer
38 TupleType = tuple
39 ListType = list
40 DictType = DictionaryType = dict
42 def _f(): pass
43 FunctionType = type(_f)
44 LambdaType = type(lambda: None) # Same as FunctionType
45 try:
46 CodeType = type(_f.func_code)
47 except RuntimeError:
48 # Execution in restricted environment
49 pass
51 def _g():
52 yield 1
53 GeneratorType = type(_g())
55 class _C:
56 def _m(self): pass
57 ClassType = type(_C)
58 UnboundMethodType = type(_C._m) # Same as MethodType
59 _x = _C()
60 InstanceType = type(_x)
61 MethodType = type(_x._m)
63 BuiltinFunctionType = type(len)
64 BuiltinMethodType = type([].append) # Same as BuiltinFunctionType
66 ModuleType = type(sys)
67 FileType = file
68 XRangeType = xrange
70 try:
71 raise TypeError
72 except TypeError:
73 try:
74 tb = sys.exc_info()[2]
75 TracebackType = type(tb)
76 FrameType = type(tb.tb_frame)
77 except AttributeError:
78 # In the restricted environment, exc_info returns (None, None,
79 # None) Then, tb.tb_frame gives an attribute error
80 pass
81 tb = None; del tb
83 SliceType = slice
84 EllipsisType = type(Ellipsis)
86 DictProxyType = type(TypeType.__dict__)
87 NotImplementedType = type(NotImplemented)
89 # Extension types defined in a C helper module. XXX There may be no
90 # equivalent in implementations other than CPython, so it seems better to
91 # leave them undefined then to set them to e.g. None.
92 try:
93 import _types
94 except ImportError:
95 pass
96 else:
97 GetSetDescriptorType = type(_types.Helper.getter)
98 MemberDescriptorType = type(_types.Helper.member)
99 del _types
101 del sys, _f, _g, _C, _x # Not for export