[pypy-svn] r5038 - in pypy/trunk/src/pypy: module module/test objspace/std

arigo at codespeak.net arigo at codespeak.net
Thu Jun 10 19:16:39 CEST 2004


Author: arigo
Date: Thu Jun 10 19:16:33 2004
New Revision: 5038

Modified:
   pypy/trunk/src/pypy/module/__builtin__interp.py
   pypy/trunk/src/pypy/module/__builtin__module.py
   pypy/trunk/src/pypy/module/test/test_builtin.py
   pypy/trunk/src/pypy/module/test/test_newstyleclasses.py
   pypy/trunk/src/pypy/objspace/std/objecttype.py
   pypy/trunk/src/pypy/objspace/std/objspace.py
Log:
- fixed super to use __getattribute__ instead of __getattr__
- corresponding tests
- added object.__init__()


Modified: pypy/trunk/src/pypy/module/__builtin__interp.py
==============================================================================
--- pypy/trunk/src/pypy/module/__builtin__interp.py	(original)
+++ pypy/trunk/src/pypy/module/__builtin__interp.py	Thu Jun 10 19:16:33 2004
@@ -301,8 +301,3 @@
 def setattr(w_object, w_name, w_val):
     space.setattr(w_object, w_name, w_val)
     return space.w_None
-
-def _pypy_get(w_value, w_self, w_class=None):   # XXX temporary
-    if w_class is None:
-        w_class = space.w_None
-    return space.get(w_value, w_self, w_class)

Modified: pypy/trunk/src/pypy/module/__builtin__module.py
==============================================================================
--- pypy/trunk/src/pypy/module/__builtin__module.py	(original)
+++ pypy/trunk/src/pypy/module/__builtin__module.py	Thu Jun 10 19:16:33 2004
@@ -563,6 +563,7 @@
 # it exposes the same special attributes as CPython's.
 class super(object):
     def __init__(self, type, obj=None):
+        # XXX check the arguments
         self.__thisclass__ = type
         self.__self__ = obj
         if obj is not None and isinstance(obj, type):
@@ -570,14 +571,18 @@
         else:
             self.__self_class__ = obj
     def __get__(self, obj, type=None):
-        if self.__self__ is None and obj is not None:
-            return super(self.__thisclass__, obj)
+        ga = object.__getattribute__
+        if ga(self, '__self__') is None and obj is not None:
+            return super(ga(self, '__thisclass__'), obj)
         else:
             return self
-    def __getattr__(self, attr):
-        mro = iter(self.__self_class__.__mro__)
+    def __getattribute__(self, attr):
+        d = object.__getattribute__(self, '__dict__')
+        if attr in d:
+            return d[attr]   # for __self__, __thisclass__, __self_class__
+        mro = iter(d['__self_class__'].__mro__)
         for cls in mro:
-            if cls is self.__thisclass__:
+            if cls is d['__thisclass__']:
                 break
         # Note: mro is an iterator, so the second loop
         # picks up where the first one left off!
@@ -587,7 +592,7 @@
             except KeyError:
                 continue
             if hasattr(x, '__get__'):
-                x = x.__get__(self.__self__, type(self.__self__))
+                x = x.__get__(d['__self__'], type(d['__self__']))
             return x
         raise AttributeError, attr
 

Modified: pypy/trunk/src/pypy/module/test/test_builtin.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_builtin.py	(original)
+++ pypy/trunk/src/pypy/module/test/test_builtin.py	Thu Jun 10 19:16:33 2004
@@ -230,22 +230,6 @@
         self.assertRaises(TypeError, hash, [])
         self.assertRaises(TypeError, hash, {})
 
-    def test_super(self):
-        class A:
-            def f(self):
-                return 'A'
-        class B(A):
-            def f(self):
-                return 'B' + super(B,self).f()
-        class C(A):
-            def f(self):
-                return 'C' + super(C,self).f()
-        class D(B, C):
-            def f(self):
-                return 'D' + super(D,self).f()
-        d = D()
-        self.assertEquals(d.f(), "DBCA")
-
         
 class TestInternal(testit.IntTestCase):
 

Modified: pypy/trunk/src/pypy/module/test/test_newstyleclasses.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_newstyleclasses.py	(original)
+++ pypy/trunk/src/pypy/module/test/test_newstyleclasses.py	Thu Jun 10 19:16:33 2004
@@ -36,7 +36,7 @@
         self.assertEquals(d.f("abc"), (D, "abc"))
         self.assertEquals(D.f("abc"), (D, "abc"))
 
-    def xtest_property_simple(self):
+    def test_property_simple(self):
         
         class a(object):
             def _get(self): return 42
@@ -48,5 +48,30 @@
         self.assertRaises(AttributeError, setattr, a1, 'name', 42)
         self.assertRaises(KeyError, delattr, a1, 'name')
 
+    def test_super(self):
+        class A:
+            def f(self):
+                return 'A'
+        class B(A):
+            def f(self):
+                return 'B' + super(B,self).f()
+        class C(A):
+            def f(self):
+                return 'C' + super(C,self).f()
+        class D(B, C):
+            def f(self):
+                return 'D' + super(D,self).f()
+        d = D()
+        self.assertEquals(d.f(), "DBCA")
+
+    def test_super_metaclass(self):
+        class xtype(type):
+            def __init__(self, name, bases, dict):
+                super(xtype, self).__init__(name, bases, dict)
+        A = xtype('A', (), {})
+        self.assert_(isinstance(A, xtype))
+        a = A()
+        self.assert_(isinstance(a, A))
+
 if __name__ == '__main__':
     testit.main()

Modified: pypy/trunk/src/pypy/objspace/std/objecttype.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/objecttype.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/objecttype.py	Thu Jun 10 19:16:33 2004
@@ -26,6 +26,9 @@
     w_obj = W_ObjectObject(space)
     return space.w_object.check_user_subclass(w_type, w_obj)
 
+def descr__init__(space, *args_w, **kwds_w):
+    pass   # XXX 2.2. behavior: ignoring all arguments
+
 # ____________________________________________________________
 
 object_typedef = StdTypeDef("object", [],
@@ -37,4 +40,5 @@
     __hash__ = gateway.interp2app(descr__hash__),
     __class__ = GetSetProperty(descr__class__),
     __new__ = newmethod(descr__new__),
+    __init__ = gateway.interp2app(descr__init__),
     )

Modified: pypy/trunk/src/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/objspace.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/objspace.py	Thu Jun 10 19:16:33 2004
@@ -237,7 +237,7 @@
         SlotWrapperType = type(type(None).__repr__)
         if isinstance(x, (types.FunctionType, types.BuiltinFunctionType, SlotWrapperType)):
             return W_BuiltinFunctionObject(self, x)
-        #print "cpython wrapping %r" % (x,)
+        print "cpython wrapping %r" % (x,)
         #if hasattr(x, '__bases__'): 
         #    print "cpython wrapping a class %r (%s)" % (x, type(x))
             #raise TypeError, "cannot wrap classes"



More information about the Pypy-commit mailing list