[pypy-svn] r5611 - in pypy/trunk/src/pypy: interpreter/test module

mwh at codespeak.net mwh at codespeak.net
Thu Jul 22 17:39:52 CEST 2004


Author: mwh
Date: Thu Jul 22 17:39:52 2004
New Revision: 5611

Modified:
   pypy/trunk/src/pypy/interpreter/test/test_class.py
   pypy/trunk/src/pypy/module/__builtin__module.py
Log:
harden super against instances that define __getattribute__ (this is
actually quite likely, it's good practice for classes that do this to
use super() in their implementations...).
test for same.


Modified: pypy/trunk/src/pypy/interpreter/test/test_class.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/test/test_class.py	(original)
+++ pypy/trunk/src/pypy/interpreter/test/test_class.py	Thu Jul 22 17:39:52 2004
@@ -126,5 +126,15 @@
         self.assertEquals(C.meth_doc.__doc__, """this is a docstring""")
         self.assertEquals(c.meth_doc.__doc__, """this is a docstring""")
 
+    def test_getattribute(self):
+        class C:
+            def __getattribute__(self, attr):
+                if attr == 'one':
+                    return 'two'
+                return super(C, self).__getattribute__(attr)
+        c = C()
+        self.assertEquals(c.one, "two")
+        self.assertRaises(AttributeError, getattr, c, "two")
+
 if __name__ == '__main__':
     testit.main()

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 Jul 22 17:39:52 2004
@@ -581,7 +581,7 @@
         self.__thisclass__ = type
         self.__self__ = obj
         if obj is not None and isinstance(obj, type):
-            self.__self_class__ = obj.__class__
+            self.__self_class__ = object.__getattribute__(obj, "__class__")
         else:
             self.__self_class__ = obj
     def __get__(self, obj, type=None):



More information about the Pypy-commit mailing list