[pypy-svn] r40998 - in pypy/dist/pypy/lib: . test2

hpk at codespeak.net hpk at codespeak.net
Thu Mar 22 00:06:41 CET 2007


Author: hpk
Date: Thu Mar 22 00:06:40 2007
New Revision: 40998

Modified:
   pypy/dist/pypy/lib/test2/test_tputil.py
   pypy/dist/pypy/lib/tputil.py
Log:
remove type attribute from operation (get it with type(operation.proxyobj))


Modified: pypy/dist/pypy/lib/test2/test_tputil.py
==============================================================================
--- pypy/dist/pypy/lib/test2/test_tputil.py	(original)
+++ pypy/dist/pypy/lib/test2/test_tputil.py	Thu Mar 22 00:06:40 2007
@@ -12,6 +12,18 @@
         raises(TypeError, "make_proxy(f)")
         raises(TypeError, "make_proxy(f, None, None)")
 
+    def test_repr(self):
+        from tputil import make_proxy 
+        l = []
+        def func(operation): 
+            l.append(repr(operation))
+            return operation.delegate()
+        tp = make_proxy(func, obj=[])
+        tp.append(3)
+        for rep in l:
+            assert isinstance(rep, str)
+            assert rep.find("list") != -1
+
     def test_virtual_proxy(self):
         from tputil import make_proxy 
         l = []
@@ -38,8 +50,7 @@
         def func(operation):
             return operation.delegate()
         l = make_proxy(func, obj=[]) 
-        excinfo = raises(AttributeError, "l.asdasd")
-        assert str(excinfo).find("asdasd") != -1
+        raises(AttributeError, "l.asdasd")
 
     def test_proxy_double(self): 
         from tputil import make_proxy

Modified: pypy/dist/pypy/lib/tputil.py
==============================================================================
--- pypy/dist/pypy/lib/tputil.py	(original)
+++ pypy/dist/pypy/lib/tputil.py	Thu Mar 22 00:06:40 2007
@@ -18,27 +18,27 @@
         'controller' callable.  The proxy will appear 
         as a completely regular instance of the given 
         type but all operations on it are send to the 
-        specified controller - which receices on 
-        ProxyOperation instance on each such call.  A non-specified 
-        type will default to type(obj) if obj is specified. 
+        specified controller - which receives on 
+        ProxyOperation instance on each such call.  
+        A non-specified type will default to type(obj) 
+        if obj is specified. 
     """
     if type is _dummy: 
         if obj is _dummy: 
-            raise TypeError("you must specify a type or an instance obj") 
+            raise TypeError("you must specify a type or an instance obj of it") 
         type = origtype(obj) 
     def perform(opname, *args, **kwargs):
-        operation = ProxyOperation(tp, type, obj, opname, args, kwargs)
+        operation = ProxyOperation(tp, obj, opname, args, kwargs)
         return controller(operation) 
     tp = tproxy(type, perform) 
     return tp 
 
 class ProxyOperation(object):
-    def __init__(self, proxyobj, type, obj, opname, args, kwargs):
+    def __init__(self, proxyobj, obj, opname, args, kwargs):
         self.proxyobj = proxyobj
         self.opname = opname 
         self.args = args
         self.kwargs = kwargs
-        self.type = type 
         if obj is not _dummy: 
             self.obj = obj 
 
@@ -64,5 +64,6 @@
         return res 
 
     def __repr__(self):
-        return "<ProxyOperation %s(*%r, **%r) %x>" %(
-                    self.opname, self.args, self.kwargs, id(self))
+        return "<ProxyOperation %s.%s(*%r, **%r) %x>" %(
+                    type(self.proxyobj).__name__, self.opname, 
+                    self.args, self.kwargs, id(self.proxyobj))



More information about the Pypy-commit mailing list