diff -crN Lib/new.py Lib.new/new.py *** Lib/new.py Thu Jan 1 02:00:00 1970 --- Lib.new/new.py Sat Jun 15 10:36:33 2002 *************** *** 0 **** --- 1,4 ---- + """This module is no longer required except for backward compatibility. + Objects of most types can now be created by calling the type object. """ + + from types import classobj, code, function, instance, instancemethod, module diff -crN Lib/types.py Lib.new/types.py *** Lib/types.py Sat Jun 15 11:18:39 2002 --- Lib.new/types.py Sat Jun 15 11:12:25 2002 *************** *** 1,6 **** """Define names for all type symbols known in the standard interpreter. ! Types that are part of optional modules (e.g. array) are not listed. """ import sys --- 1,9 ---- """Define names for all type symbols known in the standard interpreter. ! Types that are part of optional modules (e.g. array) are not listed. Each ! type appears under two names: one identical to its __name__ attribute and ! a longer, capitalized name ending with Type. e.g. 'int' and 'IntegerType' ! The long names are for backward compatibility and their use is deprecated. """ import sys *************** *** 9,89 **** # iterator. Don't check the type! Use hasattr to check for both # "__iter__" and "next" attributes instead. NoneType = type(None) - TypeType = type - ObjectType = object - IntType = int - LongType = long - FloatType = float - BooleanType = bool try: ! ComplexType = complex ! except NameError: pass - StringType = str - - # StringTypes is already outdated. Instead of writing "type(x) in - # types.StringTypes", you should use "isinstance(x, basestring)". But - # we keep around for compatibility with Python 2.2. try: ! UnicodeType = unicode ! StringTypes = (StringType, UnicodeType) ! except NameError: ! StringTypes = (StringType,) ! ! BufferType = buffer ! ! TupleType = tuple ! ListType = list ! DictType = DictionaryType = dict def _f(): pass ! FunctionType = type(_f) ! LambdaType = type(lambda: None) # Same as FunctionType try: ! CodeType = type(_f.func_code) except RuntimeError: # Execution in restricted environment pass def g(): yield 1 ! GeneratorType = type(g()) del g class _C: def _m(self): pass ! ClassType = type(_C) ! UnboundMethodType = type(_C._m) # Same as MethodType _x = _C() ! InstanceType = type(_x) ! MethodType = type(_x._m) ! BuiltinFunctionType = type(len) ! BuiltinMethodType = type([].append) # Same as BuiltinFunctionType ! ModuleType = type(sys) ! FileType = file ! XRangeType = xrange try: raise TypeError except TypeError: try: tb = sys.exc_info()[2] ! TracebackType = type(tb) ! FrameType = type(tb.tb_frame) except AttributeError: # In the restricted environment, exc_info returns (None, None, # None) Then, tb.tb_frame gives an attribute error pass tb = None; del tb ! SliceType = slice ! EllipsisType = type(Ellipsis) ! DictProxyType = type(TypeType.__dict__) del sys, _f, _C, _x # Not for export --- 12,119 ---- # iterator. Don't check the type! Use hasattr to check for both # "__iter__" and "next" attributes instead. + from __builtin__ import basestring, bool, buffer, classmethod, dict, \ + enumerate, file, float, int, list, long, object, property, slice, \ + staticmethod, str, super, tuple, type, xrange + NoneType = type(None) try: ! from __builtin__ import complex ! except ImportError: pass try: ! from __builtin__ import unicode ! except ImportError: ! pass def _f(): pass ! function = type(_f) try: ! code = type(_f.func_code) except RuntimeError: # Execution in restricted environment pass def g(): yield 1 ! generator = type(g()) del g class _C: def _m(self): pass ! classobj = type(_C) _x = _C() ! instance = type(_x) ! instancemethod = type(_x._m) ! builtin_function_or_method = type(len) ! module = type(sys) try: raise TypeError except TypeError: try: tb = sys.exc_info()[2] ! traceback = type(tb) ! frame = type(tb.tb_frame) except AttributeError: # In the restricted environment, exc_info returns (None, None, # None) Then, tb.tb_frame gives an attribute error pass tb = None; del tb ! ellipsis = type(Ellipsis) ! dictproxy = type(type.__dict__) del sys, _f, _C, _x # Not for export + + # Long names (for backward compatibility) + BooleanType = bool + BufferType = buffer + BuiltinFunctionType = builtin_function_or_method + BuiltinMethodType = builtin_function_or_method + ClassType = classobj + try: + CodeType = code + except NameError: + pass + try: + ComplexType = complex + except NameError: + pass + DictProxyType = dictproxy + DictType = DictionaryType = dict + EllipsisType = ellipsis + FileType = file + FloatType = float + try: + FrameType = frame + except NameError: + pass + FunctionType = function + GeneratorType = generator + InstanceType = instance + IntType = int + LambdaType = function + ListType = list + LongType = long + MethodType = instancemethod + ModuleType = module + ObjectType = object + SliceType = slice + StringType = str + TracebackType = traceback + TupleType = tuple + TypeType = type + UnboundMethodType = instancemethod + try: + UnicodeType = unicode + StringTypes = (str, unicode) + except NameError: + StringTypes = (str,) + XRangeType = xrange +