~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Lib/types.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
Define names for built-in types that aren't directly accessible as a builtin.
 
3
"""
 
4
import sys
 
5
 
 
6
# Iterators in Python aren't a matter of type but of protocol.  A large
 
7
# and changing number of builtin types implement *some* flavor of
 
8
# iterator.  Don't check the type!  Use hasattr to check for both
 
9
# "__iter__" and "__next__" attributes instead.
 
10
 
 
11
def _f(): pass
 
12
FunctionType = type(_f)
 
13
LambdaType = type(lambda: None)         # Same as FunctionType
 
14
CodeType = type(_f.__code__)
 
15
 
 
16
def _g():
 
17
    yield 1
 
18
GeneratorType = type(_g())
 
19
 
 
20
class _C:
 
21
    def _m(self): pass
 
22
MethodType = type(_C()._m)
 
23
 
 
24
BuiltinFunctionType = type(len)
 
25
BuiltinMethodType = type([].append)     # Same as BuiltinFunctionType
 
26
 
 
27
ModuleType = type(sys)
 
28
 
 
29
try:
 
30
    raise TypeError
 
31
except TypeError:
 
32
    tb = sys.exc_info()[2]
 
33
    TracebackType = type(tb)
 
34
    FrameType = type(tb.tb_frame)
 
35
    tb = None; del tb
 
36
 
 
37
# For Jython, the following two types are identical
 
38
GetSetDescriptorType = type(FunctionType.__code__)
 
39
MemberDescriptorType = type(FunctionType.__globals__)
 
40
 
 
41
del sys, _f, _g, _C,                              # Not for export