[pypy-svn] r72589 - pypy/branch/cpython-extension/pypy/interpreter

xoraxax at codespeak.net xoraxax at codespeak.net
Mon Mar 22 19:54:15 CET 2010


Author: xoraxax
Date: Mon Mar 22 19:54:14 2010
New Revision: 72589

Modified:
   pypy/branch/cpython-extension/pypy/interpreter/typedef.py
Log:
Reapplied r72583.

Modified: pypy/branch/cpython-extension/pypy/interpreter/typedef.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/typedef.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/typedef.py	Mon Mar 22 19:54:14 2010
@@ -301,7 +301,10 @@
 
 # ____________________________________________________________
 
-def make_descr_typecheck_wrapper(func, extraargs=(), cls=None):
+def make_descr_typecheck_wrapper(func, extraargs=(), cls=None, cpy_property=False):
+    extra_arg = ""
+    if cpy_property:
+        extra_arg = "property, "
     if func is None:
         return None
     if cls is None:
@@ -318,12 +321,12 @@
         #print "<CHECK", func.__module__ or '?', func.__name__
         assert cls.startswith('<'),"pythontype typecheck should begin with <"
         source = """
-        def descr_typecheck_%(name)s(space, w_obj, %(extra)s):
+        def descr_typecheck_%(name)s(%(extra_arg)sspace, w_obj, %(extra)s):
             if not space.is_true(space.isinstance(w_obj, space.w_%(cls_name)s)):
                 # xxx improve msg
                 msg =  "descriptor is for '%(expected)s'"
                 raise OperationError(space.w_TypeError, space.wrap(msg))
-            return %(name)s(space, w_obj, %(extra)s)
+            return %(name)s(%(extra_arg)sspace, w_obj, %(extra)s)
         """
         cls_name = cls[1:]
         expected = repr(cls_name)
@@ -331,9 +334,9 @@
         cls_name = cls.__name__
         assert issubclass(cls, Wrappable)
         source = """
-        def descr_typecheck_%(name)s(space, w_obj, %(extra)s):
+        def descr_typecheck_%(name)s(%(extra_arg)sspace, w_obj, %(extra)s):
             obj = space.descr_self_interp_w(%(cls_name)s, w_obj)
-            return %(name)s(space, obj, %(extra)s)
+            return %(name)s(%(extra_arg)sspace, obj, %(extra)s)
         """
         miniglobals[cls_name] = cls
     
@@ -376,12 +379,13 @@
     return res
 
 class GetSetProperty(Wrappable):
-    def __init__(self, fget, fset=None, fdel=None, doc=None, cls=None):
+    def __init__(self, fget, fset=None, fdel=None, doc=None, cls=None, cpy_property=False):
         "NOT_RPYTHON: initialization-time only"
         objclass_getter, cls = make_objclass_getter(fget, cls)
-        fget = make_descr_typecheck_wrapper(fget, cls=cls)
-        fset = make_descr_typecheck_wrapper(fset, ('w_value',), cls=cls)
-        fdel = make_descr_typecheck_wrapper(fdel, cls=cls)
+        fget = make_descr_typecheck_wrapper(fget, cls=cls, cpy_property=cpy_property)
+        fset = make_descr_typecheck_wrapper(fset, ('w_value',), cls=cls,
+                cpy_property=cpy_property)
+        fdel = make_descr_typecheck_wrapper(fdel, cls=cls, cpy_property=cpy_property)
         self.fget = fget
         self.fset = fset
         self.fdel = fdel
@@ -389,7 +393,8 @@
         self.reqcls = cls
         self.name = '<generic property>'
         self.objclass_getter = objclass_getter
-    
+        self.cpy_property = cpy_property
+
     def descr_property_get(space, property, w_obj, w_cls=None):
         """property.__get__(obj[, type]) -> value
         Read the value of the property of the given obj."""
@@ -400,7 +405,10 @@
             return space.wrap(property)
         else:
             try:
-                return property.fget(space, w_obj)
+                if property.cpy_property:
+                    return property.fget(property, space, w_obj)
+                else:
+                    return property.fget(space, w_obj)
             except DescrMismatch, e:
                 return w_obj.descr_call_mismatch(space, '__getattribute__',\
                     property.reqcls, Arguments(space, [w_obj,
@@ -414,7 +422,10 @@
             raise OperationError(space.w_TypeError,
                                  space.wrap("readonly attribute"))
         try:
-            fset(space, w_obj, w_value)
+            if property.cpy_property:
+                fset(property, space, w_obj, w_value)
+            else:
+                fset(space, w_obj, w_value)
         except DescrMismatch, e:
             w_obj.descr_call_mismatch(space, '__setattr__',\
                 property.reqcls, Arguments(space, [w_obj,
@@ -428,7 +439,10 @@
             raise OperationError(space.w_AttributeError,
                                  space.wrap("cannot delete attribute"))
         try:
-            fdel(space, w_obj)
+            if property.cpy_property:
+                fdel(space, w_obj)
+            else:
+                fdel(property, space, w_obj)
         except DescrMismatch, e:
             w_obj.descr_call_mismatch(space, '__delattr__',\
                 property.reqcls, Arguments(space, [w_obj,



More information about the Pypy-commit mailing list