[pypy-svn] r9980 - pypy/dist/pypy/objspace/std

arigo at codespeak.net arigo at codespeak.net
Mon Mar 21 02:29:58 CET 2005


Author: arigo
Date: Mon Mar 21 02:29:58 2005
New Revision: 9980

Modified:
   pypy/dist/pypy/objspace/std/typeobject.py
   pypy/dist/pypy/objspace/std/typetype.py
Log:
Fix the __base__ attribute of types.


Modified: pypy/dist/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typeobject.py	(original)
+++ pypy/dist/pypy/objspace/std/typeobject.py	Mon Mar 21 02:29:58 2005
@@ -20,11 +20,14 @@
         w_self.dict_w = dict_w
         w_self.ensure_static__new__()
         w_self.nslots = 0
+        w_self.w_bestbase = None
 
         if overridetypedef is not None:
             w_self.instancetypedef = overridetypedef
             w_self.hasdict = overridetypedef.hasdict
             w_self.w__flags__ = space.wrap(0) # not a heaptype
+            if overridetypedef.base is not None:
+                w_self.w_bestbase = space.gettypeobject(overridetypedef.base)
         else:
             w_self.w__flags__ = space.wrap(_HEAPTYPE)
             # find the most specific typedef
@@ -33,7 +36,9 @@
                 if not space.is_true(space.isinstance(w_base, space.w_type)):
                     continue
                 if issubtypedef(w_base.instancetypedef, instancetypedef):
-                    instancetypedef = w_base.instancetypedef
+                    if instancetypedef is not w_base.instancetypedef:
+                        instancetypedef = w_base.instancetypedef
+                        w_self.w_bestbase = w_base
                 elif not issubtypedef(instancetypedef, w_base.instancetypedef):
                     raise OperationError(space.w_TypeError,
                                 space.wrap("instance layout conflicts in "
@@ -64,6 +69,7 @@
                 w_self.hasdict = w_self.hasdict or w_base.hasdict
             if w_most_derived_base_with_slots:
                 nslots = w_most_derived_base_with_slots.nslots
+                self.w_bestbase = w_most_derived_base_with_slots
             else:
                 nslots = 0
   

Modified: pypy/dist/pypy/objspace/std/typetype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typetype.py	(original)
+++ pypy/dist/pypy/objspace/std/typetype.py	Mon Mar 21 02:29:58 2005
@@ -73,13 +73,12 @@
 
 def descr__base(space, w_type):
     w_type = _check(space, w_type)
-    if w_type is space.w_object:
-        return space.w_None
-    b = w_type.instancetypedef.base
-    if b is not None:
-        return space.gettypeobject(b)
-    else:
+    if w_type.w_bestbase is not None:
+        return w_type.w_bestbase
+    elif w_type is not space.w_object:
         return space.w_object
+    else:
+        return space.w_None
 
 def descr__doc(space, w_type):
     w_type = _check(space, w_type)



More information about the Pypy-commit mailing list