[pypy-svn] r12297 - in pypy/dist/pypy/module: builtin test

arigo at codespeak.net arigo at codespeak.net
Sun May 15 17:00:21 CEST 2005


Author: arigo
Date: Sun May 15 17:00:21 2005
New Revision: 12297

Modified:
   pypy/dist/pypy/module/builtin/app_descriptor.py
   pypy/dist/pypy/module/test/test_newstyleclasses.py
Log:
super() is definitely tricky to get right...  A hard-to-find typo ('typ' vs
'type') and a type(_self_) instead of a _self_class_ prevented it from working
with class methods.



Modified: pypy/dist/pypy/module/builtin/app_descriptor.py
==============================================================================
--- pypy/dist/pypy/module/builtin/app_descriptor.py	(original)
+++ pypy/dist/pypy/module/builtin/app_descriptor.py	Sun May 15 17:00:21 2005
@@ -121,7 +121,7 @@
     def __init__(self, typ, obj=None):
         if obj is None:
             objcls = None        # unbound super object
-        elif _issubtype(type(obj), type) and _issubtype(obj, type):
+        elif _issubtype(type(obj), type) and _issubtype(obj, typ):
             objcls = obj         # special case for class methods
         elif _issubtype(type(obj), typ):
             objcls = type(obj)   # normal case
@@ -134,9 +134,8 @@
         self.__self__ = obj
         self.__self_class__ = objcls
     def __get__(self, obj, type=None):
-        ga = object.__getattribute__
-        if ga(self, '__self__') is None and obj is not None:
-            return super(ga(self, '__thisclass__'), obj)
+        if super.__self__.__get__(self) is None and obj is not None:
+            return super(super.__thisclass__.__get__(self), obj)
         else:
             return self
     def __getattribute__(self, attr):
@@ -157,6 +156,8 @@
                     continue
                 if hasattr(x, '__get__'):
                     _self_ = super.__self__.__get__(self)
-                    x = x.__get__(_self_, type(_self_))
+                    if _self_ is _self_class_:
+                        _self_ = None   # performs an unbound __get__
+                    x = x.__get__(_self_, _self_class_)
                 return x
         return object.__getattribute__(self, attr)     # fall-back

Modified: pypy/dist/pypy/module/test/test_newstyleclasses.py
==============================================================================
--- pypy/dist/pypy/module/test/test_newstyleclasses.py	(original)
+++ pypy/dist/pypy/module/test/test_newstyleclasses.py	Sun May 15 17:00:21 2005
@@ -69,3 +69,14 @@
         assert isinstance(A, xtype)
         a = A()
         assert isinstance(a, A)
+
+    def test_super_classmethod(self):
+        class A(object):
+            def f(cls):
+                return cls
+            f = classmethod(f)
+        class B(A):
+            def f(cls):
+                return [cls, super(B, cls).f()]
+            f = classmethod(f)
+        assert B().f() == [B, B]



More information about the Pypy-commit mailing list