Mercurial > cpython-lru_cache-weakref
annotate Lib/types.py @ 27998:e27f58a50737 legacy-trunk
SF bug #690377: Dud footnote reference in distutils docs
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 21 Feb 2003 02:47:09 +0000 |
| parents | c7df225e4e4a |
| children | e4cc78884fc4 |
| 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 | 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 | 42 def _f(): pass |
| 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 |
|
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
|
45 try: |
|
24845968323f
Added some try-excepts so that it can be imported in restricted mode
Guido van Rossum <guido@python.org>
parents:
4403
diff
changeset
|
46 CodeType = type(_f.func_code) |
|
19172
cb346baedad6
Only catch the errors that can actually occur, as reported in bug #411881.
Martin v. Löwis <martin@v.loewis.de>
parents:
19071
diff
changeset
|
47 except RuntimeError: |
|
cb346baedad6
Only catch the errors that can actually occur, as reported in bug #411881.
Martin v. Löwis <martin@v.loewis.de>
parents:
19071
diff
changeset
|
48 # Execution in restricted environment |
|
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
|
49 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
|
50 |
|
18273
9e326c9e6be5
Teach the types module about generators. Thanks to James Althoff on the
Tim Peters <tim.peters@gmail.com>
parents:
11988
diff
changeset
|
51 def g(): |
|
9e326c9e6be5
Teach the types module about generators. Thanks to James Althoff on the
Tim Peters <tim.peters@gmail.com>
parents:
11988
diff
changeset
|
52 yield 1 |
|
9e326c9e6be5
Teach the types module about generators. Thanks to James Althoff on the
Tim Peters <tim.peters@gmail.com>
parents:
11988
diff
changeset
|
53 GeneratorType = type(g()) |
|
9e326c9e6be5
Teach the types module about generators. Thanks to James Althoff on the
Tim Peters <tim.peters@gmail.com>
parents:
11988
diff
changeset
|
54 del g |
|
9e326c9e6be5
Teach the types module about generators. Thanks to James Althoff on the
Tim Peters <tim.peters@gmail.com>
parents:
11988
diff
changeset
|
55 |
| 1917 | 56 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
|
57 def _m(self): pass |
| 1917 | 58 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
|
59 UnboundMethodType = type(_C._m) # Same as MethodType |
| 1917 | 60 _x = _C() |
| 61 InstanceType = type(_x) | |
| 62 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
|
63 |
| 1917 | 64 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
|
65 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
|
66 |
|
0a60460e99f0
Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 ModuleType = type(sys) |
|
19894
51cc82605d32
SF bug [#460467] file objects should be subclassable.
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
68 FileType = file |
|
23695
6266f1bd1ab9
Skip Montanaro's patch, SF 559833, exposing xrange type in builtins.
Raymond Hettinger <python@rcn.com>
parents:
23502
diff
changeset
|
69 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
|
70 |
|
0a60460e99f0
Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 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
|
72 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
|
73 except TypeError: |
|
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
|
74 try: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
75 tb = sys.exc_info()[2] |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
76 TracebackType = type(tb) |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
77 FrameType = type(tb.tb_frame) |
|
19172
cb346baedad6
Only catch the errors that can actually occur, as reported in bug #411881.
Martin v. Löwis <martin@v.loewis.de>
parents:
19071
diff
changeset
|
78 except AttributeError: |
|
cb346baedad6
Only catch the errors that can actually occur, as reported in bug #411881.
Martin v. Löwis <martin@v.loewis.de>
parents:
19071
diff
changeset
|
79 # In the restricted environment, exc_info returns (None, None, |
|
cb346baedad6
Only catch the errors that can actually occur, as reported in bug #411881.
Martin v. Löwis <martin@v.loewis.de>
parents:
19071
diff
changeset
|
80 # None) Then, tb.tb_frame gives an attribute error |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
81 pass |
|
6347
2656d1eea792
Use sys.exc_info() where needed.
Guido van Rossum <guido@python.org>
parents:
6235
diff
changeset
|
82 tb = None; 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
|
83 |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23695
diff
changeset
|
84 SliceType = slice |
|
4403
3b3f7c3f6da2
Ellipses -> Ellipsis rename (the dictionary really says that it should
Guido van Rossum <guido@python.org>
parents:
4402
diff
changeset
|
85 EllipsisType = type(Ellipsis) |
|
4402
1d275cd42c9b
Added Slice and Ellipses types.
Guido van Rossum <guido@python.org>
parents:
3385
diff
changeset
|
86 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18609
diff
changeset
|
87 DictProxyType = type(TypeType.__dict__) |
|
27803
c7df225e4e4a
[ 683376 ] Adding NotImplementedType to types.py
Just van Rossum <just@letterror.com>
parents:
23868
diff
changeset
|
88 NotImplementedType = type(NotImplemented) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18609
diff
changeset
|
89 |
|
22719
fa0ac845929b
Remove some now-obsolete generator future statements.
Tim Peters <tim.peters@gmail.com>
parents:
21129
diff
changeset
|
90 del sys, _f, _C, _x # Not for export |
