[pypy-svn] r34222 - in pypy/dist/pypy/objspace/std: . test

arigo at codespeak.net arigo at codespeak.net
Sun Nov 5 12:21:53 CET 2006


Author: arigo
Date: Sun Nov  5 12:21:51 2006
New Revision: 34222

Modified:
   pypy/dist/pypy/objspace/std/objecttype.py
   pypy/dist/pypy/objspace/std/test/test_typeobject.py
   pypy/dist/pypy/objspace/std/typeobject.py
Log:
Assignment to __class__ was too permissive.  Fix test and add checks.


Modified: pypy/dist/pypy/objspace/std/objecttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objecttype.py	(original)
+++ pypy/dist/pypy/objspace/std/objecttype.py	Sun Nov  5 12:21:51 2006
@@ -28,7 +28,7 @@
         raise OperationError(space.w_TypeError,
                              space.wrap("__class__ assignment: only for heap types"))
     w_oldcls = space.type(w_obj)
-    if w_oldcls.get_layout() == w_newcls.get_layout() and w_oldcls.hasdict == w_newcls.hasdict:
+    if w_oldcls.get_full_instance_layout() == w_newcls.get_full_instance_layout():
         w_obj.setclass(space, w_newcls)
     else:
         raise OperationError(space.w_TypeError,

Modified: pypy/dist/pypy/objspace/std/test/test_typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_typeobject.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_typeobject.py	Sun Nov  5 12:21:51 2006
@@ -404,7 +404,7 @@
         class Z1(A):
             pass
         class Z2(A):
-            __slots__ = ['__dict__']
+            __slots__ = ['__dict__', '__weakref__']
         z1 = Z1()
         z1.__class__ = Z2
         assert z1.__class__ == Z2

Modified: pypy/dist/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typeobject.py	(original)
+++ pypy/dist/pypy/objspace/std/typeobject.py	Sun Nov  5 12:21:51 2006
@@ -225,6 +225,11 @@
             return w_bestbase.get_layout()
         return w_self
 
+    # compute a tuple that fully describes the instance layout
+    def get_full_instance_layout(w_self):
+        w_layout = w_self.get_layout()
+        return (w_layout, w_self.hasdict, w_self.needsdel, w_self.weakrefable)
+
     def compute_mro(w_self):
         return compute_C3_mro(w_self.space, w_self)
 



More information about the Pypy-commit mailing list