blob: da0e59748781afa4572e4f10a326a49bc9bcd6a2 [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
Skip Montanaro012ed5d2002-05-21 23:17:12 +000019BooleanType = bool
Guido van Rossum0f6f8121996-02-13 00:04:31 +000020try:
Martin v. Löwisff885562001-08-08 16:02:01 +000021 ComplexType = complex
Guido van Rossum0f6f8121996-02-13 00:04:31 +000022except NameError:
Guido van Rossum898c9151997-09-04 22:12:34 +000023 pass
Guido van Rossum85d89451994-06-23 11:53:27 +000024
Martin v. Löwisff885562001-08-08 16:02:01 +000025StringType = str
Martin v. Löwis339d0f72001-08-17 18:39:25 +000026try:
27 UnicodeType = unicode
Martin v. Löwis8b6bd422001-12-02 12:08:06 +000028 StringTypes = (StringType, UnicodeType)
Martin v. Löwis339d0f72001-08-17 18:39:25 +000029except NameError:
Martin v. Löwis8b6bd422001-12-02 12:08:06 +000030 StringTypes = (StringType,)
Martin v. Löwis339d0f72001-08-17 18:39:25 +000031
Guido van Rossum36561c51999-03-19 19:08:03 +000032BufferType = type(buffer(''))
Guido van Rossum85d89451994-06-23 11:53:27 +000033
Martin v. Löwisff885562001-08-08 16:02:01 +000034TupleType = tuple
Tim Peters6d6c1a32001-08-02 04:15:00 +000035ListType = list
Tim Petersa427a2b2001-10-29 22:25:45 +000036DictType = DictionaryType = dict
Guido van Rossum85d89451994-06-23 11:53:27 +000037
Guido van Rossumadc940e1994-09-29 10:04:43 +000038def _f(): pass
39FunctionType = type(_f)
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000040LambdaType = type(lambda: None) # Same as FunctionType
Guido van Rossum898c9151997-09-04 22:12:34 +000041try:
42 CodeType = type(_f.func_code)
Martin v. Löwis58682b72001-08-11 15:02:57 +000043except RuntimeError:
44 # Execution in restricted environment
Guido van Rossum898c9151997-09-04 22:12:34 +000045 pass
Guido van Rossum85d89451994-06-23 11:53:27 +000046
Tim Peters3e7b1a02001-06-25 19:46:25 +000047def g():
48 yield 1
49GeneratorType = type(g())
50del g
51
Guido van Rossumadc940e1994-09-29 10:04:43 +000052class _C:
Guido van Rossum898c9151997-09-04 22:12:34 +000053 def _m(self): pass
Guido van Rossumadc940e1994-09-29 10:04:43 +000054ClassType = type(_C)
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000055UnboundMethodType = type(_C._m) # Same as MethodType
Guido van Rossumadc940e1994-09-29 10:04:43 +000056_x = _C()
57InstanceType = type(_x)
58MethodType = type(_x._m)
Guido van Rossum85d89451994-06-23 11:53:27 +000059
Guido van Rossumadc940e1994-09-29 10:04:43 +000060BuiltinFunctionType = type(len)
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000061BuiltinMethodType = type([].append) # Same as BuiltinFunctionType
Guido van Rossum85d89451994-06-23 11:53:27 +000062
63ModuleType = type(sys)
Tim Peters59c9a642001-09-13 05:38:56 +000064FileType = file
Raymond Hettingerc4c453f2002-06-05 23:12:45 +000065XRangeType = xrange
Guido van Rossum85d89451994-06-23 11:53:27 +000066
67try:
Guido van Rossum898c9151997-09-04 22:12:34 +000068 raise TypeError
Guido van Rossum85d89451994-06-23 11:53:27 +000069except TypeError:
Guido van Rossum898c9151997-09-04 22:12:34 +000070 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000071 tb = sys.exc_info()[2]
72 TracebackType = type(tb)
73 FrameType = type(tb.tb_frame)
Martin v. Löwis58682b72001-08-11 15:02:57 +000074 except AttributeError:
75 # In the restricted environment, exc_info returns (None, None,
76 # None) Then, tb.tb_frame gives an attribute error
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000077 pass
Guido van Rossumf15d1591997-09-29 23:22:12 +000078 tb = None; del tb
Guido van Rossum85d89451994-06-23 11:53:27 +000079
Guido van Rossum8741b2b1996-10-11 16:00:06 +000080SliceType = type(slice(0))
Guido van Rossume449af71996-10-11 16:25:41 +000081EllipsisType = type(Ellipsis)
Guido van Rossum8741b2b1996-10-11 16:00:06 +000082
Tim Peters6d6c1a32001-08-02 04:15:00 +000083DictProxyType = type(TypeType.__dict__)
84
Tim Peters496563a2002-04-01 00:28:59 +000085del sys, _f, _C, _x # Not for export