[pypy-svn] r50989 - in pypy/dist/pypy/objspace: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Jan 24 19:57:10 CET 2008


Author: cfbolz
Date: Thu Jan 24 19:57:10 2008
New Revision: 50989

Modified:
   pypy/dist/pypy/objspace/reflective.py
   pypy/dist/pypy/objspace/test/test_reflective.py
Log:
make the interface more uniform: always pass in a space.


Modified: pypy/dist/pypy/objspace/reflective.py
==============================================================================
--- pypy/dist/pypy/objspace/reflective.py	(original)
+++ pypy/dist/pypy/objspace/reflective.py	Thu Jan 24 19:57:10 2008
@@ -111,7 +111,6 @@
 def proxymaker(space, opname, parentfn):
     if opname in DontWrapMe:
         return None
-    want_spaceaccess = True # changed below
     def user_hook(*args_w):
         w_rspace = get_reflective_space(space)
         if w_rspace is not None:
@@ -122,12 +121,9 @@
                     if not e.match(space, space.w_AttributeError):
                         raise
                 else:
-                    if want_spaceaccess:
-                        spaceaccess = W_SpaceAccess(space, w_rspace)
-                        w_spaceaccess = space.wrap(spaceaccess)
-                        return space.call_function(w_f, w_spaceaccess, *args_w)
-                    else:
-                        return space.call_function(w_f, *args_w)
+                    spaceaccess = W_SpaceAccess(space, w_rspace)
+                    w_spaceaccess = space.wrap(spaceaccess)
+                    return space.call_function(w_f, w_spaceaccess, *args_w)
             finally:
                 reset_reflective_space(space, w_rspace)
         return None
@@ -139,7 +135,6 @@
             if w_newobj is not None:
                 return w_newobj
             return w_obj
-        want_spaceaccess = False
     elif opname.startswith("new"):
         def fn(*args):
             w_obj = parentfn(*args)
@@ -147,7 +142,6 @@
             if w_newobj is not None:
                 return w_newobj
             return w_obj
-        want_spaceaccess = False
     elif opname == "is_w":
         def fn(w_obj1, w_obj2):
             return space.is_true(space.is_(w_obj1, w_obj2))
@@ -157,7 +151,6 @@
             if w_newobj is not None:
                 w_obj = w_newobj
             return parentfn(w_obj)
-        want_spaceaccess = False
     elif opname == "call_args":
         def fn(w_callable, args):
             w_rspace = get_reflective_space(space)

Modified: pypy/dist/pypy/objspace/test/test_reflective.py
==============================================================================
--- pypy/dist/pypy/objspace/test/test_reflective.py	(original)
+++ pypy/dist/pypy/objspace/test/test_reflective.py	Thu Jan 24 19:57:10 2008
@@ -51,7 +51,7 @@
     def test_newdict(self):
         from __pypy__ import set_reflectivespace
         class Space:
-            def newdict(self, d):
+            def newdict(self, space, d):
                 d['surprise'] = 42
                 return d
 
@@ -64,7 +64,7 @@
     def test_newlist(self):
         from __pypy__ import set_reflectivespace
         class Space:
-            def newlist(self, l):
+            def newlist(self, space, l):
                 l.append(len(l))
                 return l
 
@@ -104,7 +104,7 @@
     def test_typed_unwrap(self):
         from __pypy__ import set_reflectivespace
         class Space:
-            def int_w(self, i):
+            def int_w(self, space, i):
                 if isinstance(i, basestring):
                     return int(i)
                 return i
@@ -240,3 +240,31 @@
         def f(x, **kwds):
             return x + kwds['y'] * 2
         f(y=2)(3) == 7
+
+    def test_logicspace(self):
+        from __pypy__ import set_reflectivespace
+        NotBound = object()
+        class Var(object):
+            def __init__(self):
+                self.boundto = NotBound
+        def bind(var, obj):
+            XXX # never called? :-)
+        forcing_args = {
+            'setattr': 2,
+            'setitem': 2,
+            'get': 2,
+        }
+        class UnboundVariable(Exception):
+            pass
+        class Space(object):
+            def convert(self, obj):
+                if isinstance(obj, Var):
+                    if obj.boundto is not NotBound:
+                        return obj
+                    raise UnboundVariable
+            def __getattr__(self, name):
+                if name.startswith("new"):
+                    raise AttributeError
+                def f(self, space, *args):
+                    pass
+                



More information about the Pypy-commit mailing list