annotate Lib/types.py @ 58765:2ba7677bfa95 legacy-trunk

testCopysign was defined twice in test_math; combine the definitions
author Mark Dickinson <dickinsm@gmail.com>
date Sat, 06 Feb 2010 23:11:25 +0000
parents 02950d580808
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11707
6f4146846337 The third and final doc-string sweep by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 10429
diff changeset
1 """Define names for all type symbols known in the standard interpreter.
6f4146846337 The third and final doc-string sweep by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 10429
diff changeset
2
6f4146846337 The third and final doc-string sweep by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 10429
diff changeset
3 Types that are part of optional modules (e.g. array) are not listed.
6f4146846337 The third and final doc-string sweep by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 10429
diff changeset
4 """
1680
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 import sys
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
20097
a381ab0f9d28 SF [#463737] Add types.CallableIterType
Tim Peters <tim.peters@gmail.com>
parents: 19894
diff changeset
7 # Iterators in Python aren't a matter of type but of protocol. A large
a381ab0f9d28 SF [#463737] Add types.CallableIterType
Tim Peters <tim.peters@gmail.com>
parents: 19894
diff changeset
8 # and changing number of builtin types implement *some* flavor of
a381ab0f9d28 SF [#463737] Add types.CallableIterType
Tim Peters <tim.peters@gmail.com>
parents: 19894
diff changeset
9 # iterator. Don't check the type! Use hasattr to check for both
a381ab0f9d28 SF [#463737] Add types.CallableIterType
Tim Peters <tim.peters@gmail.com>
parents: 19894
diff changeset
10 # "__iter__" and "next" attributes instead.
a381ab0f9d28 SF [#463737] Add types.CallableIterType
Tim Peters <tim.peters@gmail.com>
parents: 19894
diff changeset
11
1680
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 NoneType = type(None)
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18609
diff changeset
13 TypeType = type
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18609
diff changeset
14 ObjectType = object
1680
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
15
19071
764923d985a7 Patch #449083: Use builtins to initalize the module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
16 IntType = int
764923d985a7 Patch #449083: Use builtins to initalize the module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
17 LongType = long
764923d985a7 Patch #449083: Use builtins to initalize the module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
18 FloatType = float
23502
dc3a7f98d4ed add BooleanType
Skip Montanaro <skip@pobox.com>
parents: 22719
diff changeset
19 BooleanType = bool
3385
d5532a71b454 better way to define ComplexType
Guido van Rossum <guido@python.org>
parents: 3351
diff changeset
20 try:
19071
764923d985a7 Patch #449083: Use builtins to initalize the module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
21 ComplexType = complex
3385
d5532a71b454 better way to define ComplexType
Guido van Rossum <guido@python.org>
parents: 3351
diff changeset
22 except NameError:
6235
24845968323f Added some try-excepts so that it can be imported in restricted mode
Guido van Rossum <guido@python.org>
parents: 4403
diff changeset
23 pass
1680
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
24
19071
764923d985a7 Patch #449083: Use builtins to initalize the module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
25 StringType = str
23868
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 23695
diff changeset
26
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 23695
diff changeset
27 # StringTypes is already outdated. Instead of writing "type(x) in
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 23695
diff changeset
28 # types.StringTypes", you should use "isinstance(x, basestring)". But
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 23695
diff changeset
29 # we keep around for compatibility with Python 2.2.
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19172
diff changeset
30 try:
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19172
diff changeset
31 UnicodeType = unicode
21129
a13a4393f45c Patch #487455: make types.StringTypes a tuple.
Martin v. Löwis <martin@v.loewis.de>
parents: 20754
diff changeset
32 StringTypes = (StringType, UnicodeType)
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19172
diff changeset
33 except NameError:
21129
a13a4393f45c Patch #487455: make types.StringTypes a tuple.
Martin v. Löwis <martin@v.loewis.de>
parents: 20754
diff changeset
34 StringTypes = (StringType,)
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19172
diff changeset
35
23868
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 23695
diff changeset
36 BufferType = buffer
1680
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
37
19071
764923d985a7 Patch #449083: Use builtins to initalize the module.
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
38 TupleType = tuple
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18609
diff changeset
39 ListType = list
20754
272336648d1f Rename "dictionary" (type and constructor) to "dict".
Tim Peters <tim.peters@gmail.com>
parents: 20115
diff changeset
40 DictType = DictionaryType = dict
1680
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
1917
014a1fb9c646 Cosmetic changes
Guido van Rossum <guido@python.org>
parents: 1680
diff changeset
42 def _f(): pass
014a1fb9c646 Cosmetic changes
Guido van Rossum <guido@python.org>
parents: 1680
diff changeset
43 FunctionType = type(_f)
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6347
diff changeset
44 LambdaType = type(lambda: None) # Same as FunctionType
55744
b6bf2a5f49dd restricted environments are no more
Benjamin Peterson <benjamin@python.org>
parents: 46360
diff changeset
45 CodeType = type(_f.func_code)
1680
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
46
32726
e4cc78884fc4 Oops! Restored the pickle test to test_pyclbr, but changed types.py so
Tim Peters <tim.peters@gmail.com>
parents: 27803
diff changeset
47 def _g():
18273
9e326c9e6be5 Teach the types module about generators. Thanks to James Althoff on the
Tim Peters <tim.peters@gmail.com>
parents: 11988
diff changeset
48 yield 1
32726
e4cc78884fc4 Oops! Restored the pickle test to test_pyclbr, but changed types.py so
Tim Peters <tim.peters@gmail.com>
parents: 27803
diff changeset
49 GeneratorType = type(_g())
18273
9e326c9e6be5 Teach the types module about generators. Thanks to James Althoff on the
Tim Peters <tim.peters@gmail.com>
parents: 11988
diff changeset
50
1917
014a1fb9c646 Cosmetic changes
Guido van Rossum <guido@python.org>
parents: 1680
diff changeset
51 class _C:
6235
24845968323f Added some try-excepts so that it can be imported in restricted mode
Guido van Rossum <guido@python.org>
parents: 4403
diff changeset
52 def _m(self): pass
1917
014a1fb9c646 Cosmetic changes
Guido van Rossum <guido@python.org>
parents: 1680
diff changeset
53 ClassType = type(_C)
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6347
diff changeset
54 UnboundMethodType = type(_C._m) # Same as MethodType
1917
014a1fb9c646 Cosmetic changes
Guido van Rossum <guido@python.org>
parents: 1680
diff changeset
55 _x = _C()
014a1fb9c646 Cosmetic changes
Guido van Rossum <guido@python.org>
parents: 1680
diff changeset
56 InstanceType = type(_x)
014a1fb9c646 Cosmetic changes
Guido van Rossum <guido@python.org>
parents: 1680
diff changeset
57 MethodType = type(_x._m)
1680
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
58
1917
014a1fb9c646 Cosmetic changes
Guido van Rossum <guido@python.org>
parents: 1680
diff changeset
59 BuiltinFunctionType = type(len)
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6347
diff changeset
60 BuiltinMethodType = type([].append) # Same as BuiltinFunctionType
1680
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 ModuleType = type(sys)
19894
51cc82605d32 SF bug [#460467] file objects should be subclassable.
Tim Peters <tim.peters@gmail.com>
parents: 19343
diff changeset
63 FileType = file
23695
6266f1bd1ab9 Skip Montanaro's patch, SF 559833, exposing xrange type in builtins.
Raymond Hettinger <python@rcn.com>
parents: 23502
diff changeset
64 XRangeType = xrange
1680
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
65
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 try:
6235
24845968323f Added some try-excepts so that it can be imported in restricted mode
Guido van Rossum <guido@python.org>
parents: 4403
diff changeset
67 raise TypeError
1680
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 except TypeError:
55745
02950d580808 remove more code for restricted execution
Benjamin Peterson <benjamin@python.org>
parents: 55744
diff changeset
69 tb = sys.exc_info()[2]
02950d580808 remove more code for restricted execution
Benjamin Peterson <benjamin@python.org>
parents: 55744
diff changeset
70 TracebackType = type(tb)
02950d580808 remove more code for restricted execution
Benjamin Peterson <benjamin@python.org>
parents: 55744
diff changeset
71 FrameType = type(tb.tb_frame)
02950d580808 remove more code for restricted execution
Benjamin Peterson <benjamin@python.org>
parents: 55744
diff changeset
72 del tb
1680
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
73
23868
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 23695
diff changeset
74 SliceType = slice
4403
3b3f7c3f6da2 Ellipses -> Ellipsis rename (the dictionary really says that it should
Guido van Rossum <guido@python.org>
parents: 4402
diff changeset
75 EllipsisType = type(Ellipsis)
4402
1d275cd42c9b Added Slice and Ellipses types.
Guido van Rossum <guido@python.org>
parents: 3385
diff changeset
76
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18609
diff changeset
77 DictProxyType = type(TypeType.__dict__)
27803
c7df225e4e4a [ 683376 ] Adding NotImplementedType to types.py
Just van Rossum <just@letterror.com>
parents: 23868
diff changeset
78 NotImplementedType = type(NotImplemented)
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 18609
diff changeset
79
46360
1f15463af98c Issue 2408: remove the _types module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 39226
diff changeset
80 # For Jython, the following two types are identical
1f15463af98c Issue 2408: remove the _types module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 39226
diff changeset
81 GetSetDescriptorType = type(FunctionType.func_code)
1f15463af98c Issue 2408: remove the _types module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 39226
diff changeset
82 MemberDescriptorType = type(FunctionType.func_globals)
39226
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 32726
diff changeset
83
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 32726
diff changeset
84 del sys, _f, _g, _C, _x # Not for export