[Python-3000-checkins] r46393 - in python/branches/p3yk: Doc/lib/libnew.tex Doc/lib/libtypes.tex Lib/copy.py Lib/dis.py Lib/new.py Lib/pickle.py Lib/pickletools.py Lib/test/output/test_new Lib/test/test_new.py Lib/types.py Lib/xmlrpclib.py

guido.van.rossum python-3000-checkins at python.org
Fri May 26 21:12:42 CEST 2006


Author: guido.van.rossum
Date: Fri May 26 21:12:38 2006
New Revision: 46393

Modified:
   python/branches/p3yk/Doc/lib/libnew.tex
   python/branches/p3yk/Doc/lib/libtypes.tex
   python/branches/p3yk/Lib/copy.py
   python/branches/p3yk/Lib/dis.py
   python/branches/p3yk/Lib/new.py
   python/branches/p3yk/Lib/pickle.py
   python/branches/p3yk/Lib/pickletools.py
   python/branches/p3yk/Lib/test/output/test_new
   python/branches/p3yk/Lib/test/test_new.py
   python/branches/p3yk/Lib/types.py
   python/branches/p3yk/Lib/xmlrpclib.py
Log:
SF patch 1495675: Remove types.InstanceType and new.instance
(Collin Winter)


Modified: python/branches/p3yk/Doc/lib/libnew.tex
==============================================================================
--- python/branches/p3yk/Doc/lib/libnew.tex	(original)
+++ python/branches/p3yk/Doc/lib/libnew.tex	Fri May 26 21:12:38 2006
@@ -16,14 +16,6 @@
 
 The \module{new} module defines the following functions:
 
-\begin{funcdesc}{instance}{class\optional{, dict}}
-This function creates an instance of \var{class} with dictionary
-\var{dict} without calling the \method{__init__()} constructor.  If
-\var{dict} is omitted or \code{None}, a new, empty dictionary is
-created for the new instance.  Note that there are no guarantees that
-the object will be in a consistent state.
-\end{funcdesc}
-
 \begin{funcdesc}{instancemethod}{function, instance, class}
 This function will return a method object, bound to \var{instance}, or
 unbound if \var{instance} is \code{None}.  \var{function} must be

Modified: python/branches/p3yk/Doc/lib/libtypes.tex
==============================================================================
--- python/branches/p3yk/Doc/lib/libtypes.tex	(original)
+++ python/branches/p3yk/Doc/lib/libtypes.tex	Fri May 26 21:12:38 2006
@@ -122,10 +122,6 @@
 The type of user-defined classes.
 \end{datadesc}
 
-\begin{datadesc}{InstanceType}
-The type of instances of user-defined classes.
-\end{datadesc}
-
 \begin{datadesc}{MethodType}
 The type of methods of user-defined class instances.
 \end{datadesc}

Modified: python/branches/p3yk/Lib/copy.py
==============================================================================
--- python/branches/p3yk/Lib/copy.py	(original)
+++ python/branches/p3yk/Lib/copy.py	Fri May 26 21:12:38 2006
@@ -119,26 +119,6 @@
 if PyStringMap is not None:
     d[PyStringMap] = _copy_with_copy_method
 
-def _copy_inst(x):
-    if hasattr(x, '__copy__'):
-        return x.__copy__()
-    if hasattr(x, '__getinitargs__'):
-        args = x.__getinitargs__()
-        y = x.__class__(*args)
-    else:
-        y = _EmptyClass()
-        y.__class__ = x.__class__
-    if hasattr(x, '__getstate__'):
-        state = x.__getstate__()
-    else:
-        state = x.__dict__
-    if hasattr(y, '__setstate__'):
-        y.__setstate__(state)
-    else:
-        y.__dict__.update(state)
-    return y
-d[types.InstanceType] = _copy_inst
-
 del d
 
 def deepcopy(x, memo=None, _nil=[]):
@@ -273,29 +253,6 @@
         # aha, this is the first one :-)
         memo[id(memo)]=[x]
 
-def _deepcopy_inst(x, memo):
-    if hasattr(x, '__deepcopy__'):
-        return x.__deepcopy__(memo)
-    if hasattr(x, '__getinitargs__'):
-        args = x.__getinitargs__()
-        args = deepcopy(args, memo)
-        y = x.__class__(*args)
-    else:
-        y = _EmptyClass()
-        y.__class__ = x.__class__
-    memo[id(x)] = y
-    if hasattr(x, '__getstate__'):
-        state = x.__getstate__()
-    else:
-        state = x.__dict__
-    state = deepcopy(state, memo)
-    if hasattr(y, '__setstate__'):
-        y.__setstate__(state)
-    else:
-        y.__dict__.update(state)
-    return y
-d[types.InstanceType] = _deepcopy_inst
-
 def _reconstruct(x, info, deep, memo=None):
     if isinstance(info, str):
         return x

Modified: python/branches/p3yk/Lib/dis.py
==============================================================================
--- python/branches/p3yk/Lib/dis.py	(original)
+++ python/branches/p3yk/Lib/dis.py	Fri May 26 21:12:38 2006
@@ -18,8 +18,6 @@
     if x is None:
         distb()
         return
-    if type(x) is types.InstanceType:
-        x = x.__class__
     if hasattr(x, 'im_func'):
         x = x.im_func
     if hasattr(x, 'func_code'):

Modified: python/branches/p3yk/Lib/new.py
==============================================================================
--- python/branches/p3yk/Lib/new.py	(original)
+++ python/branches/p3yk/Lib/new.py	Fri May 26 21:12:38 2006
@@ -6,7 +6,6 @@
 
 from types import ClassType as classobj
 from types import FunctionType as function
-from types import InstanceType as instance
 from types import MethodType as instancemethod
 from types import ModuleType as module
 

Modified: python/branches/p3yk/Lib/pickle.py
==============================================================================
--- python/branches/p3yk/Lib/pickle.py	(original)
+++ python/branches/p3yk/Lib/pickle.py	Fri May 26 21:12:38 2006
@@ -687,46 +687,6 @@
                 write(SETITEM)
             # else tmp is empty, and we're done
 
-    def save_inst(self, obj):
-        cls = obj.__class__
-
-        memo  = self.memo
-        write = self.write
-        save  = self.save
-
-        if hasattr(obj, '__getinitargs__'):
-            args = obj.__getinitargs__()
-            len(args) # XXX Assert it's a sequence
-            _keep_alive(args, memo)
-        else:
-            args = ()
-
-        write(MARK)
-
-        if self.bin:
-            save(cls)
-            for arg in args:
-                save(arg)
-            write(OBJ)
-        else:
-            for arg in args:
-                save(arg)
-            write(INST + cls.__module__ + '\n' + cls.__name__ + '\n')
-
-        self.memoize(obj)
-
-        try:
-            getstate = obj.__getstate__
-        except AttributeError:
-            stuff = obj.__dict__
-        else:
-            stuff = getstate()
-            _keep_alive(stuff, memo)
-        save(stuff)
-        write(BUILD)
-
-    dispatch[InstanceType] = save_inst
-
     def save_global(self, obj, name=None, pack=struct.pack):
         write = self.write
         memo = self.memo

Modified: python/branches/p3yk/Lib/pickletools.py
==============================================================================
--- python/branches/p3yk/Lib/pickletools.py	(original)
+++ python/branches/p3yk/Lib/pickletools.py	Fri May 26 21:12:38 2006
@@ -2071,42 +2071,58 @@
     0: (    MARK
     1: l        LIST       (MARK at 0)
     2: p    PUT        0
-    5: (    MARK
-    6: i        INST       'pickletools _Example' (MARK at 5)
-   28: p    PUT        1
-   31: (    MARK
-   32: d        DICT       (MARK at 31)
-   33: p    PUT        2
-   36: S    STRING     'value'
-   45: p    PUT        3
-   48: I    INT        42
-   52: s    SETITEM
-   53: b    BUILD
-   54: a    APPEND
-   55: g    GET        1
-   58: a    APPEND
-   59: .    STOP
+    5: c    GLOBAL     'copy_reg _reconstructor'
+   30: p    PUT        1
+   33: (    MARK
+   34: c        GLOBAL     'pickletools _Example'
+   56: p        PUT        2
+   59: c        GLOBAL     '__builtin__ object'
+   79: p        PUT        3
+   82: N        NONE
+   83: t        TUPLE      (MARK at 33)
+   84: p    PUT        4
+   87: R    REDUCE
+   88: p    PUT        5
+   91: (    MARK
+   92: d        DICT       (MARK at 91)
+   93: p    PUT        6
+   96: S    STRING     'value'
+  105: p    PUT        7
+  108: I    INT        42
+  112: s    SETITEM
+  113: b    BUILD
+  114: a    APPEND
+  115: g    GET        5
+  118: a    APPEND
+  119: .    STOP
 highest protocol among opcodes = 0
 
 >>> dis(pickle.dumps(x, 1))
     0: ]    EMPTY_LIST
     1: q    BINPUT     0
     3: (    MARK
-    4: (        MARK
-    5: c            GLOBAL     'pickletools _Example'
-   27: q            BINPUT     1
-   29: o            OBJ        (MARK at 4)
-   30: q        BINPUT     2
-   32: }        EMPTY_DICT
-   33: q        BINPUT     3
-   35: U        SHORT_BINSTRING 'value'
-   42: q        BINPUT     4
-   44: K        BININT1    42
-   46: s        SETITEM
-   47: b        BUILD
-   48: h        BINGET     2
-   50: e        APPENDS    (MARK at 3)
-   51: .    STOP
+    4: c        GLOBAL     'copy_reg _reconstructor'
+   29: q        BINPUT     1
+   31: (        MARK
+   32: c            GLOBAL     'pickletools _Example'
+   54: q            BINPUT     2
+   56: c            GLOBAL     '__builtin__ object'
+   76: q            BINPUT     3
+   78: N            NONE
+   79: t            TUPLE      (MARK at 31)
+   80: q        BINPUT     4
+   82: R        REDUCE
+   83: q        BINPUT     5
+   85: }        EMPTY_DICT
+   86: q        BINPUT     6
+   88: U        SHORT_BINSTRING 'value'
+   95: q        BINPUT     7
+   97: K        BININT1    42
+   99: s        SETITEM
+  100: b        BUILD
+  101: h        BINGET     5
+  103: e        APPENDS    (MARK at 3)
+  104: .    STOP
 highest protocol among opcodes = 1
 
 Try "the canonical" recursive-object test.

Modified: python/branches/p3yk/Lib/test/output/test_new
==============================================================================
--- python/branches/p3yk/Lib/test/output/test_new	(original)
+++ python/branches/p3yk/Lib/test/output/test_new	Fri May 26 21:12:38 2006
@@ -1,7 +1,6 @@
 test_new
 new.module()
 new.classobj()
-new.instance()
 new.instancemethod()
 new.function()
 new.code()

Modified: python/branches/p3yk/Lib/test/test_new.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_new.py	(original)
+++ python/branches/p3yk/Lib/test/test_new.py	Fri May 26 21:12:38 2006
@@ -21,22 +21,12 @@
 C = new.classobj('Spam', (Spam.Eggs,), {'get_more_yolks': get_more_yolks})
 if verbose:
     print C
-print 'new.instance()'
-c = new.instance(C, {'yolks': 3})
-if verbose:
-    print c
-o = new.instance(C)
-verify(o.__dict__ == {},
-       "new __dict__ should be empty")
-del o
-o = new.instance(C, None)
-verify(o.__dict__ == {},
-       "new __dict__ should be empty")
-del o
 
 def break_yolks(self):
     self.yolks = self.yolks - 2
 print 'new.instancemethod()'
+c = C()
+c.yolks = 3
 im = new.instancemethod(break_yolks, c, C)
 if verbose:
     print im

Modified: python/branches/p3yk/Lib/types.py
==============================================================================
--- python/branches/p3yk/Lib/types.py	(original)
+++ python/branches/p3yk/Lib/types.py	Fri May 26 21:12:38 2006
@@ -56,9 +56,7 @@
     def _m(self): pass
 ClassType = type(_C)
 UnboundMethodType = type(_C._m)         # Same as MethodType
-_x = _C()
-InstanceType = type(_x)
-MethodType = type(_x._m)
+MethodType = type(_C()._m)
 
 BuiltinFunctionType = type(len)
 BuiltinMethodType = type([].append)     # Same as BuiltinFunctionType
@@ -86,4 +84,4 @@
 DictProxyType = type(TypeType.__dict__)
 NotImplementedType = type(NotImplemented)
 
-del sys, _f, _g, _C, _x                  # Not for export
+del sys, _f, _g, _C                 # Not for export

Modified: python/branches/p3yk/Lib/xmlrpclib.py
==============================================================================
--- python/branches/p3yk/Lib/xmlrpclib.py	(original)
+++ python/branches/p3yk/Lib/xmlrpclib.py	Fri May 26 21:12:38 2006
@@ -748,7 +748,6 @@
         else:
             # store instance attributes as a struct (really?)
             self.dump_struct(value.__dict__, write)
-    dispatch[InstanceType] = dump_instance
     dispatch[DateTime] = dump_instance
     dispatch[Binary] = dump_instance
 


More information about the Python-3000-checkins mailing list