blob: 41accfc94dffc879d630a582e61ebb1225b7008c [file] [log] [blame]
Guido van Rossume7b146f2000-02-04 15:28:42 +00001"""Define names for all type symbols known in the standard interpreter.
2
3Types that are part of optional modules (e.g. array) are not listed.
4"""
Guido van Rossum85d89451994-06-23 11:53:27 +00005import sys
6
Tim Peters26991a72001-09-25 22:02:03 +00007# 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.
11
Guido van Rossum85d89451994-06-23 11:53:27 +000012NoneType = type(None)
Tim Peters6d6c1a32001-08-02 04:15:00 +000013TypeType = type
14ObjectType = object
Guido van Rossum85d89451994-06-23 11:53:27 +000015
Martin v. Löwisff885562001-08-08 16:02:01 +000016IntType = int
17LongType = long
18FloatType = float
Guido van Rossum0f6f8121996-02-13 00:04:31 +000019try:
Martin v. Löwisff885562001-08-08 16:02:01 +000020 ComplexType = complex
Guido van Rossum0f6f8121996-02-13 00:04:31 +000021except NameError:
Guido van Rossum898c9151997-09-04 22:12:34 +000022 pass
Guido van Rossum85d89451994-06-23 11:53:27 +000023
Martin v. Löwisff885562001-08-08 16:02:01 +000024StringType = str
Martin v. Löwis339d0f72001-08-17 18:39:25 +000025try:
26 UnicodeType = unicode
Martin v. Löwis8b6bd422001-12-02 12:08:06 +000027 StringTypes = (StringType, UnicodeType)
Martin v. Löwis339d0f72001-08-17 18:39:25 +000028except NameError:
Martin v. Löwis8b6bd422001-12-02 12:08:06 +000029 StringTypes = (StringType,)
Martin v. Löwis339d0f72001-08-17 18:39:25 +000030
Guido van Rossum36561c51999-03-19 19:08:03 +000031BufferType = type(buffer(''))
Guido van Rossum85d89451994-06-23 11:53:27 +000032
Martin v. Löwisff885562001-08-08 16:02:01 +000033TupleType = tuple
Tim Peters6d6c1a32001-08-02 04:15:00 +000034ListType = list
Tim Petersa427a2b2001-10-29 22:25:45 +000035DictType = DictionaryType = dict
Guido van Rossum85d89451994-06-23 11:53:27 +000036
Guido van Rossumadc940e1994-09-29 10:04:43 +000037def _f(): pass
38FunctionType = type(_f)
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000039LambdaType = type(lambda: None) # Same as FunctionType
Guido van Rossum898c9151997-09-04 22:12:34 +000040try:
41 CodeType = type(_f.func_code)
Martin v. Löwis58682b72001-08-11 15:02:57 +000042except RuntimeError:
43 # Execution in restricted environment
Guido van Rossum898c9151997-09-04 22:12:34 +000044 pass
Guido van Rossum85d89451994-06-23 11:53:27 +000045
Tim Peters3e7b1a02001-06-25 19:46:25 +000046def g():
47 yield 1
48GeneratorType = type(g())
49del g
50
Guido van Rossumadc940e1994-09-29 10:04:43 +000051class _C:
Guido van Rossum898c9151997-09-04 22:12:34 +000052 def _m(self): pass
Guido van Rossumadc940e1994-09-29 10:04:43 +000053ClassType = type(_C)
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000054UnboundMethodType = type(_C._m) # Same as MethodType
Guido van Rossumadc940e1994-09-29 10:04:43 +000055_x = _C()
56InstanceType = type(_x)
57MethodType = type(_x._m)
Guido van Rossum85d89451994-06-23 11:53:27 +000058
Guido van Rossumadc940e1994-09-29 10:04:43 +000059BuiltinFunctionType = type(len)
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000060BuiltinMethodType = type([].append) # Same as BuiltinFunctionType
Guido van Rossum85d89451994-06-23 11:53:27 +000061
62ModuleType = type(sys)
Tim Peters59c9a642001-09-13 05:38:56 +000063FileType = file
Guido van Rossum85d89451994-06-23 11:53:27 +000064XRangeType = type(xrange(0))
65
66try:
Guido van Rossum898c9151997-09-04 22:12:34 +000067 raise TypeError
Guido van Rossum85d89451994-06-23 11:53:27 +000068except TypeError:
Guido van Rossum898c9151997-09-04 22:12:34 +000069 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000070 tb = sys.exc_info()[2]
71 TracebackType = type(tb)
72 FrameType = type(tb.tb_frame)
Martin v. Löwis58682b72001-08-11 15:02:57 +000073 except AttributeError:
74 # In the restricted environment, exc_info returns (None, None,
75 # None) Then, tb.tb_frame gives an attribute error
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000076 pass
Guido van Rossumf15d1591997-09-29 23:22:12 +000077 tb = None; del tb
Guido van Rossum85d89451994-06-23 11:53:27 +000078
Guido van Rossum8741b2b1996-10-11 16:00:06 +000079SliceType = type(slice(0))
Guido van Rossume449af71996-10-11 16:25:41 +000080EllipsisType = type(Ellipsis)
Guido van Rossum8741b2b1996-10-11 16:00:06 +000081
Tim Peters6d6c1a32001-08-02 04:15:00 +000082DictProxyType = type(TypeType.__dict__)
83
Tim Peters496563a2002-04-01 00:28:59 +000084del sys, _f, _C, _x # Not for export