[pypy-svn] r70542 - in pypy/trunk/pypy/module/__builtin__: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Jan 12 18:57:21 CET 2010


Author: cfbolz
Date: Tue Jan 12 18:57:20 2010
New Revision: 70542

Modified:
   pypy/trunk/pypy/module/__builtin__/descriptor.py
   pypy/trunk/pypy/module/__builtin__/test/test_descriptor.py
Log:
issue492 testing
be a bit less crazy in property.__setattr__: prevent only the writing of the
attributes the property object has, to make it possible to sanely subclass
property.


Modified: pypy/trunk/pypy/module/__builtin__/descriptor.py
==============================================================================
--- pypy/trunk/pypy/module/__builtin__/descriptor.py	(original)
+++ pypy/trunk/pypy/module/__builtin__/descriptor.py	Tue Jan 12 18:57:20 2010
@@ -4,7 +4,7 @@
      Arguments
 from pypy.interpreter.gateway import interp2app
 from pypy.interpreter.error import OperationError
-from pypy.objspace.descroperation import object_getattribute
+from pypy.objspace.descroperation import object_getattribute, object_setattr
 from pypy.interpreter.function import StaticMethod, ClassMethod
 from pypy.interpreter.typedef import GetSetProperty, descr_get_dict, \
      descr_set_dict, interp_attrproperty_w
@@ -153,8 +153,11 @@
         # XXX kill me?  This is mostly to make tests happy, raising
         # a TypeError instead of an AttributeError and using "readonly"
         # instead of "read-only" in the error message :-/
-        raise OperationError(space.w_TypeError, space.wrap(
-            "Trying to set readonly attribute %s on property" % (attr,)))
+        if attr in ["__doc__", "fget", "fset", "fdel"]:
+            raise OperationError(space.w_TypeError, space.wrap(
+                "Trying to set readonly attribute %s on property" % (attr,)))
+        return space.call_function(object_setattr(space),
+                                   space.wrap(self), space.wrap(attr), w_value)
     setattr.unwrap_spec = ['self', ObjSpace, str, W_Root]
 
 W_Property.typedef = TypeDef(

Modified: pypy/trunk/pypy/module/__builtin__/test/test_descriptor.py
==============================================================================
--- pypy/trunk/pypy/module/__builtin__/test/test_descriptor.py	(original)
+++ pypy/trunk/pypy/module/__builtin__/test/test_descriptor.py	Tue Jan 12 18:57:20 2010
@@ -301,3 +301,13 @@
             pass
         else:
             raise Exception, "expected ZeroDivisionError from bad property"
+
+    def test_property_subclass(self):
+        class P(property):
+            pass
+
+        p = P()
+        p.name = 0
+        assert p.name == 0
+
+



More information about the Pypy-commit mailing list