annotate Lib/types.py @ 74135:9c19df6c8ea0 3.2

News entry for Issue12798
author Senthil Kumaran <senthil@uthcode.com>
date Fri, 23 Dec 2011 11:11:21 +0800
parents 2e917b0c8f6e
children c3a0197256ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44370
bce70a477f1d Fix docstring of types.py.
Georg Brandl <georg@python.org>
parents: 44049
diff changeset
1 """
bce70a477f1d Fix docstring of types.py.
Georg Brandl <georg@python.org>
parents: 44049
diff changeset
2 Define names for built-in types that aren't directly accessible as a builtin.
11707
6f4146846337 The third and final doc-string sweep by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 10429
diff changeset
3 """
1680
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 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
5
20097
a381ab0f9d28 SF [#463737] Add types.CallableIterType
Tim Peters <tim.peters@gmail.com>
parents: 19894
diff changeset
6 # 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
7 # 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
8 # iterator. Don't check the type! Use hasattr to check for both
41501
0c5019afc55b PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents: 40910
diff changeset
9 # "__iter__" and "__next__" attributes instead.
20097
a381ab0f9d28 SF [#463737] Add types.CallableIterType
Tim Peters <tim.peters@gmail.com>
parents: 19894
diff changeset
10
1917
014a1fb9c646 Cosmetic changes
Guido van Rossum <guido@python.org>
parents: 1680
diff changeset
11 def _f(): pass
014a1fb9c646 Cosmetic changes
Guido van Rossum <guido@python.org>
parents: 1680
diff changeset
12 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
13 LambdaType = type(lambda: None) # Same as FunctionType
41715
f60c877d52c8 Merged revisions 55270-55324 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41645
diff changeset
14 CodeType = type(_f.__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
15
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
16 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
17 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
18 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
19
1917
014a1fb9c646 Cosmetic changes
Guido van Rossum <guido@python.org>
parents: 1680
diff changeset
20 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
21 def _m(self): pass
38397
ac45eca8c35c SF patch 1495675: Remove types.InstanceType and new.instance
Guido van Rossum <guido@python.org>
parents: 32726
diff changeset
22 MethodType = type(_C()._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
23
1917
014a1fb9c646 Cosmetic changes
Guido van Rossum <guido@python.org>
parents: 1680
diff changeset
24 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
25 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
26
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 ModuleType = type(sys)
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
0a60460e99f0 Two new generally useful modules: types defines names for all built-in types,
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 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
30 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
31 except TypeError:
41715
f60c877d52c8 Merged revisions 55270-55324 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41645
diff changeset
32 tb = sys.exc_info()[2]
f60c877d52c8 Merged revisions 55270-55324 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41645
diff changeset
33 TracebackType = type(tb)
f60c877d52c8 Merged revisions 55270-55324 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41645
diff changeset
34 FrameType = type(tb.tb_frame)
6347
2656d1eea792 Use sys.exc_info() where needed.
Guido van Rossum <guido@python.org>
parents: 6235
diff changeset
35 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
36
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44370
diff changeset
37 # For Jython, the following two types are identical
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44370
diff changeset
38 GetSetDescriptorType = type(FunctionType.__code__)
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44370
diff changeset
39 MemberDescriptorType = type(FunctionType.__globals__)
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38397
diff changeset
40
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38397
diff changeset
41 del sys, _f, _g, _C, # Not for export