[pypy-svn] r70694 - in pypy/trunk/pypy/objspace: . test

benjamin at codespeak.net benjamin at codespeak.net
Tue Jan 19 00:24:05 CET 2010


Author: benjamin
Date: Tue Jan 19 00:24:04 2010
New Revision: 70694

Modified:
   pypy/trunk/pypy/objspace/descroperation.py
   pypy/trunk/pypy/objspace/test/test_descriptor.py
Log:
only override values in the instance dictionary if __get__ is defined

resolves issue #491


Modified: pypy/trunk/pypy/objspace/descroperation.py
==============================================================================
--- pypy/trunk/pypy/objspace/descroperation.py	(original)
+++ pypy/trunk/pypy/objspace/descroperation.py	Tue Jan 19 00:24:04 2010
@@ -35,7 +35,13 @@
         w_descr = space.lookup(w_obj, name)
         if w_descr is not None:
             if space.is_data_descr(w_descr):
-                return space.get(w_descr, w_obj)
+                # Only override if __get__ is defined, too, for compatibility
+                # with CPython.
+                w_get = space.lookup(w_descr, "__get__")
+                if w_get is not None:
+                    w_type = space.type(w_obj)
+                    return space.get_and_call_function(w_get, w_descr, w_obj,
+                                                       w_type)
             w_value = w_obj.getdictvalue_attr_is_in_class(space, name)
         else:
             w_value = w_obj.getdictvalue(space, name)

Modified: pypy/trunk/pypy/objspace/test/test_descriptor.py
==============================================================================
--- pypy/trunk/pypy/objspace/test/test_descriptor.py	(original)
+++ pypy/trunk/pypy/objspace/test/test_descriptor.py	Tue Jan 19 00:24:04 2010
@@ -12,6 +12,24 @@
         del x.f
         assert x.f() == 42
 
+    def test_set_without_get(self):
+        class Descr(object):
+
+            def __init__(self, name):
+                self.name = name
+
+            def __set__(self, obj, value):
+                obj.__dict__[self.name] = value
+        descr = Descr("a")
+
+        class X(object):
+            a = descr
+
+        x = X()
+        assert x.a is descr
+        x.a = 42
+        assert x.a == 42
+
     def test_member(self):
         class X(object):
             def __init__(self):



More information about the Pypy-commit mailing list