blob: 1bb560cb099e3a6ce9586897f2da643e3a0e9c8c [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 Rossumb09f7ed2001-07-15 21:08:29 +00005from __future__ import generators
Guido van Rossum85d89451994-06-23 11:53:27 +00006
7import sys
8
Tim Peters26991a72001-09-25 22:02:03 +00009# Iterators in Python aren't a matter of type but of protocol. A large
10# and changing number of builtin types implement *some* flavor of
11# iterator. Don't check the type! Use hasattr to check for both
12# "__iter__" and "next" attributes instead.
13
Guido van Rossum85d89451994-06-23 11:53:27 +000014NoneType = type(None)
Tim Peters6d6c1a32001-08-02 04:15:00 +000015TypeType = type
16ObjectType = object
Guido van Rossum85d89451994-06-23 11:53:27 +000017
Martin v. Löwisff885562001-08-08 16:02:01 +000018IntType = int
19LongType = long
20FloatType = float
Guido van Rossum0f6f8121996-02-13 00:04:31 +000021try:
Martin v. Löwisff885562001-08-08 16:02:01 +000022 ComplexType = complex
Guido van Rossum0f6f8121996-02-13 00:04:31 +000023except NameError:
Guido van Rossum898c9151997-09-04 22:12:34 +000024 pass
Guido van Rossum85d89451994-06-23 11:53:27 +000025
Martin v. Löwisff885562001-08-08 16:02:01 +000026StringType = str
Martin v. Löwis339d0f72001-08-17 18:39:25 +000027try:
28 UnicodeType = unicode
29 StringTypes = [StringType, UnicodeType]
30except NameError:
31 StringTypes = [StringType]
32
Guido van Rossum36561c51999-03-19 19:08:03 +000033BufferType = type(buffer(''))
Guido van Rossum85d89451994-06-23 11:53:27 +000034
Martin v. Löwisff885562001-08-08 16:02:01 +000035TupleType = tuple
Tim Peters6d6c1a32001-08-02 04:15:00 +000036ListType = list
37DictType = DictionaryType = dictionary
Guido van Rossum85d89451994-06-23 11:53:27 +000038
Guido van Rossumadc940e1994-09-29 10:04:43 +000039def _f(): pass
40FunctionType = type(_f)
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000041LambdaType = type(lambda: None) # Same as FunctionType
Guido van Rossum898c9151997-09-04 22:12:34 +000042try:
43 CodeType = type(_f.func_code)
Martin v. Löwis58682b72001-08-11 15:02:57 +000044except RuntimeError:
45 # Execution in restricted environment
Guido van Rossum898c9151997-09-04 22:12:34 +000046 pass
Guido van Rossum85d89451994-06-23 11:53:27 +000047
Tim Peters3e7b1a02001-06-25 19:46:25 +000048def g():
49 yield 1
50GeneratorType = type(g())
51del g
52
Guido van Rossumadc940e1994-09-29 10:04:43 +000053class _C:
Guido van Rossum898c9151997-09-04 22:12:34 +000054 def _m(self): pass
Guido van Rossumadc940e1994-09-29 10:04:43 +000055ClassType = type(_C)
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000056UnboundMethodType = type(_C._m) # Same as MethodType
Guido van Rossumadc940e1994-09-29 10:04:43 +000057_x = _C()
58InstanceType = type(_x)
59MethodType = type(_x._m)
Guido van Rossum85d89451994-06-23 11:53:27 +000060
Guido van Rossumadc940e1994-09-29 10:04:43 +000061BuiltinFunctionType = type(len)
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000062BuiltinMethodType = type([].append) # Same as BuiltinFunctionType
Guido van Rossum85d89451994-06-23 11:53:27 +000063
64ModuleType = type(sys)
Tim Peters59c9a642001-09-13 05:38:56 +000065FileType = file
Guido van Rossum85d89451994-06-23 11:53:27 +000066XRangeType = type(xrange(0))
67
68try:
Guido van Rossum898c9151997-09-04 22:12:34 +000069 raise TypeError
Guido van Rossum85d89451994-06-23 11:53:27 +000070except TypeError:
Guido van Rossum898c9151997-09-04 22:12:34 +000071 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000072 tb = sys.exc_info()[2]
73 TracebackType = type(tb)
74 FrameType = type(tb.tb_frame)
Martin v. Löwis58682b72001-08-11 15:02:57 +000075 except AttributeError:
76 # In the restricted environment, exc_info returns (None, None,
77 # None) Then, tb.tb_frame gives an attribute error
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000078 pass
Guido van Rossumf15d1591997-09-29 23:22:12 +000079 tb = None; del tb
Guido van Rossum85d89451994-06-23 11:53:27 +000080
Guido van Rossum8741b2b1996-10-11 16:00:06 +000081SliceType = type(slice(0))
Guido van Rossume449af71996-10-11 16:25:41 +000082EllipsisType = type(Ellipsis)
Guido van Rossum8741b2b1996-10-11 16:00:06 +000083
Tim Peters6d6c1a32001-08-02 04:15:00 +000084DictProxyType = type(TypeType.__dict__)
85
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000086del sys, _f, _C, _x # Not for export